0
我試圖根據交叉引用表的zindex屬性和類別表(在本例中稱爲'Chassis'),但出現以下錯誤:Linq to SQL/C#:如何訂購通過在lambda表達式中使用交叉引用表中的屬性
無法按類型'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));
}
我明白了。選擇方法返回一個IEnumerable,但作爲一個多到多的關係,x.E_Product_Chassis不允許簡單的選擇其屬性(egxE_Product_Chassis.Zindex)。
任何幫助將是非常讚賞...
heh。重複的答案。 – Toby 2010-06-22 14:35:23
「FirstOrDefault(),Min(),Max()」...或從集合中返回標量值的任何其他方法。只是想指出這些不是你唯一的選擇器。 – Marc 2010-06-22 14:37:44
謝謝!那就是訣竅! – user373253 2010-06-22 15:26:32