2013-02-14 27 views
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表中。

这在存储过程中很容易做到,但我试图将其构建出来,这样我就不需要执行存储过程来撤回结果。

+1

你为什么分开你的plan_patient,plan_exclusion和plan_schedule列到新表中?所有其他表格列是相同的。 – 2013-02-14 18:27:02

+0

这将有助于了解类的样子,特别是导航属性。 – 2013-02-14 22:05:54

回答

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