After many hours of bashing my head against the wall, I came up with an answer using ConvertAll<T>
If you want to use lambda expressions instead of the dynamic linq strings, you have to convert the List<DynamicNode> into List<dynamic>
//Declare the Items as a DynamicNode list List<DynamicNode> children = @Model.Children.Items;
//Declare the dynamicList type so the lambda knows that the delegate is a dynamic object List<dynamic> dynamicList = children //Cast the list of DynamicNode objects to dynamic objects by passing in the convertion //function into ConvertAll .ConvertAll<dynamic>(delegate(DynamicNode x) { return (dynamic)x; });
//Use your lambdas! (how do you pluralize lambda?) dynamicList = dynamicList.Where(x => x.location.cityid == sumNumber).ToList();
If someone else has a better idea I'll look forward to it :)
Custom Data Types and Where Clause
I have a custom data type called "location" that has cityid and regionid as properties
I'd like to create a Where clause that will filter on cityid and regionid
@Model.Children.Where("location.cityid == someNumber") doesn't work
Is there currently a way to do this?
P.s. I didn't create this custom data type, please don't flame me lol.
After many hours of bashing my head against the wall, I came up with an answer using ConvertAll<T>
If you want to use lambda expressions instead of the dynamic linq strings, you have to convert the List<DynamicNode> into List<dynamic>
//Declare the Items as a DynamicNode list
List<DynamicNode> children = @Model.Children.Items;
//Declare the dynamicList type so the lambda knows that the delegate is a dynamic object
List<dynamic> dynamicList = children
//Cast the list of DynamicNode objects to dynamic objects by passing in the convertion
//function into ConvertAll
.ConvertAll<dynamic>(delegate(DynamicNode x) { return (dynamic)x; });
//Use your lambdas! (how do you pluralize lambda?)
dynamicList = dynamicList.Where(x => x.location.cityid == sumNumber).ToList();
If someone else has a better idea I'll look forward to it :)
Not sure if it will help in your case (as you didn't develop the custom DataType_, but you might want to read Gareth's blog-post on [I]RazorDataTypeModel - Datatype Developers Property Data / Model interface
I couldn't figure how to use the IRazorDataTypeModel with my cshtml script at all
is working on a reply...