是否可以按groupby中不存在的列进行排序?
例如,我有这样的查询:
var data= from c in customers join o in orders on c.id=o.id group new { c, o } by new { o.customerid, c.FirstName, c.LastName, c.City } into customergroups orderby customergroup.select(x=>xoquantity)
但是,它给了我空的结果集..
请建议..
是的,只要表达式生成可比较的对象,就可以按任何顺序对组进行排序。 例如,您可以按最小或最大数量*订购,但不能仅按数量订购,因为组中可能有许多不同的数量。
var data= from c in customers join o in orders on c.id=o.id group new { c, o } by new { o.customerid, c.FirstName, c.LastName, c.City } into customergroups orderby customergroup.Max(x=>xoquantity);
*您也可以使用First(x=>xoquantity)
或Last(x=>xoquantity)
,但顺序是任意的。