0

我正在尝试一个 linq 语句,其中有以下四个表

table: plan
id
planname

table: patient 
Fields
id, firstname, lastname, site_id

Table: site
id,
sitename

table: plan_patient
id
site_id
patient_id

table: plan_Exclusions
id
patient_id
plan_id
site_id

table: plan_schedule
id
patient_id
plan_id
site_id

我想撤回所有未分配到计划或从计划中排除的患者。

确定患者是否未分配到计划的决定因素是他们在排除表中,他们在表中没有时间表plan_schedule并且他们不存在于plan_patient表中。

这在存储过程中很容易做到,但我正在尝试构建它,这样我就不需要执行存储过程来拉回结果。

4

1 回答 1

0

这就是我为一个复杂的情况接触多个表的方式

var MyResults =
   from hc in context.hcTypes
   from hga in context.hgaToGmuTypes
   from hq in context.hqToQuota
   from qt in context.Types
   from dd in context.ddDraws
   from dh in context.dhDraws
   where hc.Year == dtYear
        && hc.Year == hga.Year
       && hc.code == hga.code
       && hc.Year == hq.Year
       && hc.code == hq.code
       && hq.Id == qt.Id
       && qt.PrefernceCode == "Y"
       && hga.Year == dtYear
       && hga.Code == "Z"
       && hc.code == dd.code
       && dd.Code == dh.Code
       && dh.Year == dtYear
       && dh.Code == "Z" 
       && dh.Left == "P"
select new MyClass { Id = hc.Id, Huntcode = hc.Huntcode, GMU = hga.GMUTypeCode }
 ;

在你的情况下,它会是这样的:

var YourResults = 
    from pl in plan 
    from pa in patient 
    from s = site 
    from plan_patient 
    from plan_Exclusions 

    with the Where statements linking the data 
    and the Select pulling what you want
于 2013-02-14T19:53:44.827 回答