我正在尝试使用下面的efcore查询按查询进行排序
获取列的PropertyInfo,该列需要是orderedBy,使用下面的
var propertyInfo = typeof(TableVM).GetProperty("Type");EfCore查询
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
这在EfCore 2中是可行的。
通过删除LinqKit 3.1.3中的EfCore扩展进行了测试,它只对OrderBy抛出错误,声明无法将其转换为Linq
我在EfCore查询中做错了什么吗?提前感谢
发布于 2021-03-05 03:40:06
有个错误。
TableVM类具有type属性,实体具有Type属性。
因此,在TableVM类中重命名属性应该有效。
https://stackoverflow.com/questions/61635636
复制相似问题