Friday, January 04, 2013 12:26 PM
below is my sql code
DECLARE @EMPNAME VARCHAR(50);
DECLARE @EMPCITY VARCHAR(100);
SELECT T1.EMPID FROM TABLE1 AS T1 WHERE ( (@EMPNAME IS NULL || T1.EMPNAME = @EMPNAME ) && (@EMPCITY IS NULL || T1.EMPCITY = @EMPCITY) );
how do i write the same kind of query using LINQ and C#, experts please help me
Thanks In Advance, Jeyaseelan
Friday, January 04, 2013 1:59 PM
Var record = (from t in Table1
WHERE (EMPNAME IS NULL || t. EMPNAME == EMPNAME) && (EMPCITY is null || T. EMPCITY == EMPCITY)
Friday, January 04, 2013 2:05 PM
Var record = from t in Table1 where (t.EMPNAME == null || t.EMPNAME == EMPNAME) && (t.EMPCITY == null || T.EMPCITY == EMPCITY) Select t;
Hope this helps!
One good question is equivalent to ten best answers.
- Marked As Answer by Alexander SunModerator Wednesday, January 16, 2013 9:33 AM
Friday, January 04, 2013 6:17 PM
Try your query like this. It should return a collection of EMPID as the original query has.
string EMPNAME = "The String you are looking for or null"; string EMPCITY = "Emp City or null"; ObjectContextName db = new ObjectContextName(); var empIds = from T1 in db.TABLE1 where (EMPNAME IS NULL || T1.EMPNAME = EMPNAME ) && (EMPCITY IS NULL || T1.EMPCITY = EMPCITY) select T1.EMPID;
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".