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

item