Expression.Call - Calling linq extension: FirstOrDefault, Where

后端 未结 1 828
旧时难觅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?

    If not, you can't pass it to Queryable.FirstOrDefault(IQueryable).

    If it's an IEnumerable, change your code to call Enumerable.FirstOrDefault(IEnumerable):

     var result =
         Expression.Call(
             typeof(Enumerable),
             "FirstOrDefault",
             new Type[] { TypeSystem.GetElementType(property.Type) },
             property);
    

    0 讨论(0)
提交回复
热议问题