Help With A Linq Query

Posted by Sharpcnet under LINQ on 12/15/2013 | Points: 10 | Views : 1021 | Status : [Member] | Replies : 3
How can the foll. sql be written in Linq. I am using LinqToEntities,C#.
@companyID & @branchID are the parameters
select * from tblEmp e
where e.deleted = 0 and
(e.companyId = @companyID OR e.companyid is null) and
(e.branchId = @branchID OR e.branchid is null)
For now, there is a stored procedure for the same and I am using it in linq
var qry = from d in MYDB.GetData(int companyid, int branchid)
select new
{
//all reqd. columns...
}

so, is it possible to write the above in Linq, directly.




Responses

Posted by: vishalneeraj-24503 on: 12/15/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Please refer:-
http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx

http://www.youtube.com/watch?v=8nn9ctW3lAk

http://www.codeproject.com/Tips/315667/LINQ-to-SQL-Mapping-Stored-Procedure-with-Multiple

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/15/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
http://stackoverflow.com/questions/10822811/create-reusable-linq-to-sql-for-stored-procedures
http://www.mssqltips.com/sqlservertip/1542/using-stored-procedures-with-linq-to-sql/
http://www.youtube.com/watch?v=UhlTOS3xGDQ

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vinothkumar on: 4/11/2014 [Member] Starter | Points: 25

Up
0
Down
var result=from e in tblEmp
where e.deleted=0 and ((e.companyId == @companyID) || (e.companyid == null))
and ((e.branchId == @branchID) OR (e.branchid == null))

Regards,
Vinoth kumar

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response