Expression.Call - Calling linq extension: FirstOrDefault, Where

后端 未结 1 802
旧时难觅i
旧时难觅i 2021-01-18 13:07

I am trying to create the following dynamically, however I am having problems calling the extension method FirstOrDefault:

 using(var context =          


        
相关标签:
1条回答
  • 2021-01-18 13:48

    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);
    
    0 讨论(0)
提交回复
热议问题