I am trying to mock up a page using WebMatrix using WebPages under the hood. I have assigned an implicitly typed array of anonymous objects to one of the PageData keys, but I get the following error when I try to using LINQ methods on the collection:
CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Here is some sample code:
@{
PageData["Vals"] = new [] {
new { ID=1, Quantity=5 },
new { ID=2, Quantity=3 }
};
var sum = PageData["Vals"].Sum(x => x.Quantity);
}
If I first store the array in a regular object, I can use the LINQ methods on it just fine. It seems to have a problem when it comes out of PageData as a dynamic object - but I can't quite seem to figure out the secret sauce to coerce it back to the initial type.