George
George

Reputation: 101

How to convert this SQL query to Linq to Entity query?

could you help me please convert this SQL query to Linq to Entity query? Thank you

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

Upvotes: 0

Views: 862

Answers (1)

Thomas
Thomas

Reputation: 64635

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() }

Upvotes: 1

Related Questions