Entity framework - LINQ JOIN 不工作
Entity framework - LINQ JOIN not working
我有一个显示患者数据的 gridview,但我需要使用两个 tables - 目前我只将它与患者 table 及其显示的性别、种族等(带数字)绑定但我需要从 Ref table 获取这些数据。我尝试加入然后绑定它,但我没有工作,我被告知导航 属性 将完成这项工作,但没有一个教程帮助我。
帮助和建议将不胜感激。
患者和参考文献示例 table
Patient Table
Patient ID Patient Name Gender Ethnicity
1 John 0 1
Ref Table
Reference ID Domain Code Description
1 Gender 0 Male
2 Gender 1 Female
3 Ethnicity 1 White
4 Ethnicity 2 Black
这是我尝试过的加入
Dim Testing = from x In db.Patient, y In db.ref where y.Domain = "Gender"
or y.Domain = "Ethnicity"
Select x.PatientID, x.PatientName, y.Gender, y.Ethnicity
gvPatient.DataSource = Testing
gvPatient.DataBind()
为每个查找创建视图。
CREATE VIEW Gender
AS
SELECT Code, Description
FROM .Ref
WHERE Domain = 'Gender'
然后为每个查找创建实体,用 KeyAttribute 标记代码 属性。
我有一个显示患者数据的 gridview,但我需要使用两个 tables - 目前我只将它与患者 table 及其显示的性别、种族等(带数字)绑定但我需要从 Ref table 获取这些数据。我尝试加入然后绑定它,但我没有工作,我被告知导航 属性 将完成这项工作,但没有一个教程帮助我。
帮助和建议将不胜感激。
患者和参考文献示例 table
Patient Table
Patient ID Patient Name Gender Ethnicity
1 John 0 1
Ref Table
Reference ID Domain Code Description
1 Gender 0 Male
2 Gender 1 Female
3 Ethnicity 1 White
4 Ethnicity 2 Black
这是我尝试过的加入
Dim Testing = from x In db.Patient, y In db.ref where y.Domain = "Gender"
or y.Domain = "Ethnicity"
Select x.PatientID, x.PatientName, y.Gender, y.Ethnicity
gvPatient.DataSource = Testing
gvPatient.DataBind()
为每个查找创建视图。
CREATE VIEW Gender
AS
SELECT Code, Description
FROM .Ref
WHERE Domain = 'Gender'
然后为每个查找创建实体,用 KeyAttribute 标记代码 属性。