0
正如标题所述,我想orderby
结果表使用另一个表的列。orderby Count(other_table)in linq查询
var products = (from p in db.Products
join o in db.OrderDetails on p.ProductID equals o.ProductID
orderby count(o.Quantity) <-- want to do something like this
select p).Distinct().Take(8).ToList();
下面是SQL等效声明。
SELECT Products.ProductID FROM Products
INER JOIN OrderDetail on OrderDetail.ProductID = Products.ProductID
GROUP BY Products.ProductID
ORDER BY COUNT(OrderDetail.Quantity)
而且我正在得到预期的结果。但我怎样才能使用LINQ?
你有什么试过,你没有得到什么? PS:你的查询看起来很混乱。 –
你有什么等价的sql语句你想要什么? –