I have some SQL code that I want to "convert" to an entity framework 'call'.
This is the code:
select itemStatus, avg(UnitPrice) from ItemSalesHistory
where item = 'BQF09-L-Q007'
group by itemStatus
I'm new to using Entity Framework.
I have some SQL code that I want to "convert" to an entity framework 'call'.
This is the code:
select itemStatus, avg(UnitPrice) from ItemSalesHistory
where item = 'BQF09-L-Q007'
group by itemStatus
I'm new to using Entity Framework.
Yes you can. If you take a look at this answer, you can apply it to your situation:
var query = ItemSalesHistory
.Where(x => x.item == 'BQF09-L-Q007')
.GroupBy(x => x.itemStatus)
.Select(g => new { itemStatus = g.Key, avg = g.Average(x => x.UnitPrice) });