Linq to SQL Join,Order by,Group by

时间:2015-02-02 04:24:21

标签: sql sql-server linq

我有以下sql查询,工作正常。我想将此查询转换为Linq。

select a.store_id, b.name 
from stock a inner join store b on a.store_id = b.id 
group by a.store_id, b.name 
order by a.store_id desc;

id | STORE_NAME

1 |商店

2 | B商店

3 | C商店


谢谢:)

1 个答案:

答案 0 :(得分:0)

尝试使用此代码,

from a in stock
join b in store on a.store_id equals b.id
group new { a.store_id, b.name } by g into groupResult
orderby groupResult.store_id desc
select new 
{
    StoreId = groupResult.store_id, 
    Name = groupResult.name
}