no

How to Execute a Group by and Sum Query in Entity Framework

The following code is the native sql with the converted code in entity framework. It queries the sum of quantity group by branch, model, yea...

The following code is the native sql with the converted code in entity framework. It queries the sum of quantity group by branch, model, year and week no.
//native sql
select weekyear, weekno, branchid, modelid, sum(quantity) from selloutmobiles
where weekyear=2012 and weekno=1
group by weekyear, weekno, branchid, modelid

//entity framework
var count = (from aa in Context.Products
                         where aa.BranchId == branchId
                         && aa.ModelId == skuId
                         && aa.WeekYear == year
                         && aa.WeekNo == week
                         group aa by new { aa.BranchId, aa.ModelId, aa.WeekYear, aa.WeekNo }
                             into gaa
                             select gaa.Sum(aa => aa.Quantity)).FirstOrDefault();

Related

rdbms 8379665576956050023

Post a Comment Default Comments

Outsourcing

Are you looking for freelancers in the Philippines? Get in touch.

Donations

If you like what I do, you can support this channel by buying me a coffee. I would be grateful for your contribution! Your donations will help me create more FREE online courses and learning materials for programmers and remote workers.

item