2010-02-07 93 views
1

我一直在寻找,但找不到解决这个...多左加入对实体框架

这里是我的实体...

  • ContentPage(有许多ContentPageZones)
  • ContentPageZone(有一个内容)
  • 内容

我はnt通过ID查询ContentPage,并且我希望它包含所有活动的并且至少有一个活动内容(都具有IsActive bool属性)的相关ContentPageZones。如果没有可用的ContentPageZones具有活动内容,我仍然希望ContentPage带有一个空的ContentPageZones列表。

对此提出建议?

回答

0

在你的问题,你说:

ContentPageZone(有一个内容)

这意味着ContentPageZone - >含量为1 .. [0,1]。

再后来你说:

...所有相关ContentPageZones是活跃的,并且至少有一个内容是积极的......

这意味着ContentPageZone - >内容是1 .. *。

我假设第一个是正确的,但第二个查询会不同。

var q = from cp in Context.ContentPages 
     where cp.ID == someId 
     select new 
     { 
      ID = cp.ID, 
      Name = cp.Name, 
      ContentPageZones = from cpz in cp.ContentPageZones 
           where cpz.Content.IsActive 
           select new 
           { 
            ID = cpz.ID, 
            // etc. 
           } 
     }; 
+0

是,1 => [0,1] – ctorx 2010-02-10 04:04:59