Linq to SQL / C#:如何使用交叉引用表中的属性和 lambda 表达式进行排序
我试图根据交叉引用表的 zindex 属性与类别表(在本例中称为“机箱”)来订购产品列表,但出现以下错误:
无法按类型“System”订购。 Collections.Generic.IEnumerable`1[System.Int32]'。
以下是我正在使用的方法:
public IQueryable<E_Product> Product_GetList_ByChassisId(int chassisId)
{
return dc.E_Products
.Where(x => x.Deleted == false)
.Where(x => x.Published == true)
.Where(x => x.E_Product_Chassis
.Any(c => c.ChassisId == chassisId && c.Deleted == false))
.OrderBy(x => x.E_Product_Chassis.Select(c => c.Zindex));
}
我了解 .Select 方法返回 IEnumerable,但作为多对多关系,x.E_Product_Chassis不允许简单选择其属性(例如xE_Product_Chassis.Zindex)。
任何帮助将不胜感激...
I am trying to order a list of products based on the zindex property of the cross reference table with the category table (in this case called 'Chassis'), but I get the following error:
Cannot order by type 'System.Collections.Generic.IEnumerable`1[System.Int32]'.
The following is the method I am using:
public IQueryable<E_Product> Product_GetList_ByChassisId(int chassisId)
{
return dc.E_Products
.Where(x => x.Deleted == false)
.Where(x => x.Published == true)
.Where(x => x.E_Product_Chassis
.Any(c => c.ChassisId == chassisId && c.Deleted == false))
.OrderBy(x => x.E_Product_Chassis.Select(c => c.Zindex));
}
I understand the .Select method returns an IEnumerable, but being a many-to-many relationship, x.E_Product_Chassis does not allow simple selection of its properties (e.g. x.E_Product_Chassis.Zindex).
Any help would be very appreciated...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
FirstOrDefault()、Min()、Max()——使用这些函数之一从集合中选择适当的 z 索引。
FirstOrDefault(), Min(), Max() -- use one of these functions to select the appropriate z-index out of the set.