I am trying to create the following dynamically, however I am having problems calling the extension method FirstOrDefault
:
using(var context =
Are you sure e.Cars
is an IQueryable<T>?
If not, you can't pass it to Queryable.FirstOrDefault<T>(IQueryable<T>).
If it's an IEnumerable<T>, change your code to call Enumerable.FirstOrDefault<T>(IEnumerable<T>):
var result =
Expression.Call(
typeof(Enumerable),
"FirstOrDefault",
new Type[] { TypeSystem.GetElementType(property.Type) },
property);