LINQ怎样查询三个表的连接
三个表的连接怎样写呢,
两个的我是这样写的,可以正常运行,
LinqHISDBDataContext lqDB = new LinqHISDBDataContext(ConfigurationManager.ConnectionStrings["HISLinqDB_ConnectionString"].ConnectionString.ToString());
var result001 = from bed in lqDB.zy_bed_mi
join unit in lqDB.zd_unit_code
on bed.dept_sn equals unit.code
select new
{
dept_sn = unit.name,
bed_no = bed.bed_no,
bed_status = bed.bed_status,
patient_id = bed.patient_id,
sex = bed.sex,
type = bed.type
};
GridView1.DataSource = result001;
GridView1.DataBind();
但三个的我就不会写了,
非常感谢。
------解决方案--------------------var q=from a in table1
join b in table2
on a.field1 equals b.field1
join c in table2
on a.field2 equals c.field2
select new{......};
------解决方案-------------------- 一样的写法
var result001 = from bed in lqDB.zy_bed_mi
join unit in lqDB.zd_unit_code
on bed.dept_sn equals unit.code
join sc in lqDB.Categories
on unit.code equals sc.code
select new
{
dept_sn = unit.name,
bed_no = bed.bed_no,
bed_status = bed.bed_status,
patient_id = bed.patient_id,
sex = bed.sex,
type = bed.type
};
------解决方案--------------------不止两个,N个都可以
不止inner join 可以,left/group join也可以:
var result001 = from bed in lqDB.zy_bed_mi
join unit in lqDB.zd_unit_code