C# 将n-m关系联接查询转换为Linq
我有以下三个表格:C# 将n-m关系联接查询转换为Linq,c#,linq,join,C#,Linq,Join,我有以下三个表格: table patient { NID *pk Name Family } table disease { ICD_code *pk Title } table_patient_disease *-* { ID Fk_ICDcode FK_Patient } 病人和疾病之间是一种n-m关系。 我想写一个查询来选择患者及其疾病 它需要加入linq Sql纯查询是: SELECT dbo.Table_Disea
table patient
{ NID *pk
Name
Family
}
table disease
{
ICD_code *pk
Title
}
table_patient_disease *-*
{
ID
Fk_ICDcode
FK_Patient
}
病人和疾病之间是一种n-m关系。
我想写一个查询来选择患者及其疾病
它需要加入linq
Sql纯查询是:
SELECT
dbo.Table_Disease.*,
dbo.Table_PatDis.*,
dbo.Table_Patient.*
FROM
dbo.Table_Disease
INNER JOIN dbo.Table_PatDis ON dbo.Table_Disease.ICD_code = dbo.Table_PatDis.FK_Disease
INNER JOIN dbo.Table_Patient ON dbo.Table_PatDis.FK_PAtient = dbo.Table_Patient.NID
相同的Linq语句是什么
SELECT
dbo.Table_Disease.*,
dbo.Table_PatDis.*,
dbo.Table_Patient.*
FROM
dbo.Table_Disease
INNER JOIN dbo.Table_PatDis ON dbo.Table_Disease.ICD_code = dbo.Table_PatDis.FK_Disease
INNER JOIN dbo.Table_Patient ON dbo.Table_PatDis.FK_PAtient = dbo.Table_Patient.NID
将成为:
var results = (from d in DbContext.Table_Disease
join pd in DbContext.Table_PatDis on d.ICD_Code equals pd.FK_Disease
join p in DbContext.Table_Patient on pd.FK_PAtient equals p.NID
select new {d, pd, p});