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();
Post a Comment