[英]Using Entity framework across multiple tables
I am trying to a linq statement where I have the following four 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
I want to pull back all of the patients that have not been assigned to a plan or excluded from the plan. 我想撤回所有尚未分配到计划或未从计划中排除的患者。
what determines if a patient is not assigned to a plan, is that they are in the exclusion table, they don't have a schedule in the plan_schedule
table and they don't exist in the plan_patient
table. 是什么决定,如果病人没有分配给一个计划,是他们在排除表格,他们没有在时间表
plan_schedule
表的时候,不要在存在plan_patient
表。
This is so easy to do in a stored procedure, but I am trying to build this out, so that I don't need to do a stored procedure to pull back the results. 在存储过程中这样做很容易,但是我试图将其构建出来,这样就不需要执行存储过程来拉回结果。
This is how I have reached out to multiple tables for a complex 这就是我接触多个表的复杂方式
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 }
;
In your case, it would be something like: 在您的情况下,它将类似于:
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.