I am trying to a linq statement where I have the following four tables
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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.