EfCore 3.1.3 throwing Execption for OrderBy

假装没事ソ 提交于 2021-01-28 20:35:50

问题


I am trying to Order by a query using the following efcore query

Getting the PropertyInfo for the column which needs to be orderedBy using this below

var propertyInfo = typeof(TableVM).GetProperty("Type");

The EfCore Query

db.Table
 **//LinkKit Extension Method**
 .AsExpandable()
 .Where(whereClause)
 .Select(m => new TableVM
 {
    id= m.Id,
    name = m.Name,
    description = m.Description,
    type = m.Type,
    status = m.Status
})
**// Conversion of the OrderBy fails, which throws an exception saying it can't convert it into Linq query.**
.OrderBy(x => propertyInfo.GetValue(x, null))
.Skip(skip)
.Take(take)
.ToList();

C# - code to order by a property using the property name as a string

This works in EfCore 2.

Tested with removing the LinqKit extension in EfCore 3.1.3, it throws error only for OrderBy stating it can't convert it into Linq

Am I doing any mistake in the EfCore Query? Thanks in advance

来源:https://stackoverflow.com/questions/61635636/efcore-3-1-3-throwing-execption-for-orderby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!