I want to do exactly the same thing but with Where (not Add). Visual Studio told me to cast it in delegate or in tree type, but I'm stuck with that, when I try to cast it, it doesn't work. Can somebody gives me a short example of how to cast the lambda expression in delegate ?
Thank you!
Sorry for late edit.
[AllowAnonymous]
public ActionResult test()
{
Contexte contexte = new Contexte();
var listField = contexte.GetType().GetField("<offreStages>k__BackingField", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
dynamic fldVal = listField.GetValue(contexte);
fldVal.Where(os => os.id == 1);
/* Error:
Cannot use a lambda expression as an argument to a dynamically
dispatched operation without first casting it to a delegate or
expression tree type.
*/
return View();
}
From this post, it says we can use dynamic to directly call method without complicated Invoke, but as you can see, it doesn't work if we need to send a lambda expression and I just don't understand the error (how to cast it). Can somebody explain it and give me an example ?