Tech-Today
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, 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();
-
Hibernate Search Faceting
With the document available from Hibernate Search (https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#query-faceting), we should be able to implement a faceting example that returns the faceting field and its count. In the example...
-
Passing An Array Of Objects To Mssql Stored Procedure
Oftentimes you need to pass an array of objects (could be ids, types, etc) in an mssql stored procedure that you either need to insert into a table or use as filter. The following codes will explain the latter: Pass an array of integers: ALTER PROCEDURE...
-
Linq Dynamic And Or Statements
You usually need this on search form where you have to add a condition if a field is filled or not. This is how I do it: public static List Search(SearchViewModel param) { IQueryable matches = EntityMdl.SellOutMobiles; if (!string.IsNullOrEmpty(param.Client))...
-
How To Write Left Join Sql On Entity Framework
In every limitation there is always a work around. For this specific limitation on entity framework 3.5 not having a left join. This is what I came up: For example you want to: SQL: select * from contact a left join country c on a.contactid=c.contactid...
-
Implement A Stored Procedure In Entity Framework
Implement a stored procedure in Entity Framework 1.) To do this we have to create a database (name according to your preference) and add the following tables: CREATE TABLE [dbo].[Authors]( [AuthorID] [int] IDENTITY(1,1) NOT NULL, [Name] [varchar](100)...
Tech-Today