EfCore 3.1.3为OrderBy投掷执行 [英] EfCore 3.1.3 throwing Execption for OrderBy
问题描述
我正在尝试使用以下efcore查询通过查询进行订购
I am trying to Order by a query using the following efcore query
获取需要订购的列的PropertyInfo,请在下面使用此
Getting the PropertyInfo for the column which needs to be orderedBy using this below
var propertyInfo = typeof(TableVM).GetProperty("Type");
EfCore查询
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();
这在EfCore 2中有效.
This works in EfCore 2.
经过测试,删除了EfCore 3.1.3中的LinqKit扩展,它仅对OrderBy抛出错误,指出它无法将其转换为Linq
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
我在EfCore查询中犯了任何错误吗?提前致谢
Am I doing any mistake in the EfCore Query? Thanks in advance
推荐答案
有错字.
您的TableVM类具有 type
属性,而您的实体具有 Type
属性.
Your TableVM class has type
property and your Entity has Type
property.
因此,重命名TableVM类中的属性应该可以.
So, renaming the property in TableVM class should work.
这篇关于EfCore 3.1.3为OrderBy投掷执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!