如何将此SQL查询转换为Linq to Entity查询?

时间:2010-04-24 16:32:40

标签: c# linq linq-to-entities

你能帮我转发这个SQL查询到Linq to Entity查询吗?谢谢

select distinct item, count(item) as count 
from TableName 
where ColumnName = @parameter and (ColumnName2 = @parameter2 OR ColumnName3 = @parameter3)
group by item  order by item asc

1 个答案:

答案 0 :(得分:1)

from TableName in db.TableName
where TableName.Column1 == 'param1' 
    && ( TableName.Column2 == 'param2' || TableName.Column3 == 'param3' )
group item by new { TableName.Item } into t
orderby t.Key.Item
select new {  t.Key.Item,  ItemCount = t.Count() }