2012-07-11 103 views
0

我正在使用C#MVC3和实体框架。 我有一个包含2个FK的表格。 所以,我想执行这个查询:加入查询

SELECT * 
    FROM TABLE1 f, 
     TABLE2  r, 
     TABLE3  c 
WHERE f.codx = r.codx 
    AND f.cody = c.cody 

TABLE1 =包含FK的

所以,我需要他的DbSet将包括参考表.... 但是,我怎么能添加两个桌子在我的DbSet? 我收到另一类D​​bSet,并添加我查询的问题:

return ((from table1 in this.GetContext<Fake>().TABLE1.Include("TABLE2") //Here I need to Include another table, was working with just one 
     where (
     .............) 
     select).ToList<Table1>()); 

我怎样才能做到这一点?

谢谢!

回答

1

您可以链接多个.Include方法一起使用:

return ((from table1 in this.GetContext<Fake>().TABLE1.Include("TABLE2").Include("TABLE3") 
     where (
     .............) 
     select).ToList<Table1>()); 
+0

但是,我不包括表3对表2的? – 2012-07-11 20:32:50

+0

订单不相关。所有的映射都是通过模型知道的。 – 2012-07-11 20:37:57