Here are the tables:
tblEmp: EMPID EMPCODE GRADEID
-------------------------
1 c1 g1
2 c2 g2
tblGrade: GRADEID LEAVEID DAYS
-------------------------
g1 l1 10
g1 l2 20
g2 l1 30
tblLeave: LEAVEID LEAVECODE
------------------------
l1 al
l2 cl
l3 ml
I would like to get the leavecodes based on empcode. So the sql would be
select g.leaveid,l.leavecode,g.days
from tblemp e
join tblgrade g on e.gradeid = g.gradeid
join tblleave l on g.leaveid = l.leaveid
where e.empcode='c1'
Desired result:
LEAVEID LEAVETYPE DAYS
-------------------------
l1 al 10
l2 cl 20
This code gives an error - 'The name 'g' is not in scope on the left side of equals.Consider swapping the expressions on either side of equals.
public DataTable GetData()
{
var qry = from e in DB.tblemp.where(e=>e.empcode=='c1')
join g in DB.tblgrade on e.gradeid equals g.gradeid
join l in DB.tblleave on g.leaveid equals l.leaveid //error here at g.leaveid
select new
{
leaveid = g.leaveid,
leavecode = l.leavecode ?? string.empty,
days = g.days ?? 0.0
};
DataTable dt = new DataTable();
dt = qry.ToDataTable();
return dt;
}