【问题标题】:Entity framework : Bring a list of tables after comparing with other table实体框架:与其他表比较后带一个表列表
【发布时间】:2018-05-26 18:08:04
【问题描述】:

早安,

我有一个包含 5 个表格的图表。

如您所见,我有一个类别表和详细的医学研究。 还有两个类似的表:OtherStudy 和 OtherMedicalStudyDetails。 这些表还具有一些来自未包含在此图中的其他表的外键。 为了简单起见,我提供了一个看起来不太好但更容易解释我的问题的数据库图(有人可以告诉我,我应该只使用 medicalStudy 和 medicalStudy 详细信息表,不要使用其他两个,但我想请保持这样的图表)。

我想要做的是,在添加(使用 c# entityframework)一个带有 MedicalStudyDetails 的医学研究后,比较两个详细信息表,并在(MedicalStudyDetails.FK_otherTable==OtherMedicalStudyDetails.FK_otherTable&& MedicalStudyDetails.FK_anotherTable==OtherMedicalStudyDetails.FK_anotherTable) 处列出所有“OtherStudy”的列表。 .请注意,应针对添加的每个 MedicalStudyDetails 进行此比较。

有没有办法使用这样的 sintax 来提供提到的列表?

 var otherStudy= _dbContext.MedicalStudyDetails.Include(...)
            .Where(...)
            .ToList();

【问题讨论】:

  • 你知道什么是内连接吗?
  • LINQ 语句的哪一部分您不清楚?你不是在问如何使用IncludeWhere,是吗?那将是微不足道的。离题但很重要:我不了解您的数据模型(即使它是人为的)。您不需要两组(或更多组)相同的表格。所有研究只能存储在StudyStudyDetails 表中。

标签: c# asp.net-mvc entity-framework


【解决方案1】:

你不需要一个多子句内连接来实现这个吗??

from msd in _dbContext.MedicalStudyDetails
join omsd in _dbContext.OtherMedicalStudyDetails on 
    new {msd.FK_otherTable, msd.FK_anotherTable} equals new { omsd.FK_otherTable, omsd.FK_anotherTable}
where ...
select ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多