[英]Using Entity framework across multiple tables
我正在尝试使用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
表。
在存储过程中这样做很容易,但是我试图将其构建出来,这样就不需要执行存储过程来拉回结果。
这就是我接触多个表的复杂方式
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.