I want to switch my linq statement from query syntax to lambda, for me the hardest part to me to understand is the lambda join
from ru in db.rpm_usr
join ei in db.emp_info on ru.wwid equals ei.wwid
So above that query join syntax is easy but when I try to put it into lambda
This is not working for me
.Join(Rpm_scrty_emp_info, p => p.Iact_ind, j => j.Wwid
Full query:
var queryAllUsers = (from ru in db.rpm_usr
join ei in db.emp_info on ru.wwid equals ei.wwid
let cdis_eml = ei.dmn_addr + ";"
where ru.inact_ind == "N" && ei.inact_ind == "N" && ei.dmn_addr != null
orderby ei.dmn_addr
select new rpm_scrty_rpm_usr()
{
usr_id = ru.usr_id,
usr_lnm = ru.usr_lnm,
usr_pwd = ru.usr_pwd,
usr_fnm = ru.usr_fnm,
wwid = ru.wwid,
apprvr_wwid = ru.apprvr_wwid,
chg_dtm = ru.chg_dtm,
chg_usr_id = ru.chg_usr_id,
dflt_ste_id = ru.dflt_ste_id,
cre_dtm = ru.cre_dtm,
cre_usr_id = ru.cre_usr_id,
lst_pwd_chg_dtm = ru.lst_pwd_chg_dtm,
lst_accs_dtm = ru.lst_accs_dtm,
email_id = ru.email_id,
inact_ind = ru.inact_ind,
salt = ru.salt,
tel = ru.tel
}).ToList();
I'm not sure it is really "worth" it as lambda joins to me are not pretty , something like this.
I was wrong this will crate a problem with
Anonymous Type issue
DO NOT DO THIS
INSTEAD DO THIS
I personally find it easier to better understand LINQ in dot notation by breaking down the query onto separate lines.
Following on from @Tom's example above, the query breaks down as follows:
You can also follow @Tom's first example and leverage anonymous objects to return both sides of the join, or even specific properties.
If you don't have it already, I'd highly recommend the software, LINQpad. It's great for debugging LINQ and also has a built-in converter for switching between query and lambda syntax.