I am looking for the LAMBDA expression code that would do the equivalent of:
int ddl_emp = dropdownlist1.SelectedItem.Value;
myDataContext dc = new myDataContext();
var queryEmployees = from emp in dc.EMPLOYEES
from dept in dc.DEPARTMENT
where emp.empID == dc.empID
// if (ddl_emp != 0) where emp.empID == ddl_emp THIS IS WHERE I NEED THE RELATED LAMBDA EXP.
select new (emp.Fname, Dept.Department)
int ddl_emp = 0;
var queryEmployes = from e in dc.EMPLOYEES
join d in dc.DEPARTMENTs on e.empID equals d.empID
where (ddl_emp != 0 ? e.empID == ddl_emp : e.empID == d.empID)
select new { e.Fname, d.Department};
Kindly mark this post as "Answer", if it helped you.
Marked as answer by CSharper7 on May 09, 2012 05:01 PM
CSharper7
Member
2 Points
11 Posts
If statement for WHERE clause
May 09, 2012 01:34 PM|LINK
Hi All
I am looking for the LAMBDA expression code that would do the equivalent of:
int ddl_emp = dropdownlist1.SelectedItem.Value; myDataContext dc = new myDataContext(); var queryEmployees = from emp in dc.EMPLOYEES from dept in dc.DEPARTMENT where emp.empID == dc.empID // if (ddl_emp != 0) where emp.empID == ddl_emp THIS IS WHERE I NEED THE RELATED LAMBDA EXP. select new (emp.Fname, Dept.Department)Any chelp woulb be much appreciated
thanks!
MetalAsp.Net
All-Star
112157 Points
18249 Posts
Moderator
Re: If statement for WHERE clause
May 09, 2012 01:45 PM|LINK
CSharper7
Member
2 Points
11 Posts
Re: If statement for WHERE clause
May 09, 2012 01:56 PM|LINK
Thanks for you help, but can you be more specific ???
Just by pasting / adding your code I am getting ZERO results.. I dont see a CONDITION in your code
cheers
pierrefrc
Participant
947 Points
201 Posts
Re: If statement for WHERE clause
May 09, 2012 04:32 PM|LINK
Hi
You can try:
int ddl_emp = 0; var queryEmployes = from e in dc.EMPLOYEES join d in dc.DEPARTMENTs on e.empID equals d.empID where (ddl_emp != 0 ? e.empID == ddl_emp : e.empID == d.empID) select new { e.Fname, d.Department};CSharper7
Member
2 Points
11 Posts
Re: If statement for WHERE clause
May 09, 2012 05:00 PM|LINK
Thanks Pierre... It Work, life saver here!
Cheers
MetalAsp.Net
All-Star
112157 Points
18249 Posts
Moderator
Re: If statement for WHERE clause
May 09, 2012 05:02 PM|LINK