日期:2014-05-20  浏览次数:20936 次

entity里面include的表添加where语句
我有三个表,A,B,C,其中A可以通过B与C进行连接查询,使用ef时:dbquery=dbquery.Include("B.C");现在我想要加一个C的列的条件,如C.Column1=='column',使用entity该如何写呢?如果是使用sql应该为:select * from B inner join C on B.col=C.col where C.Column1='column'
------解决方案--------------------
var dbquery=from b in dbquery.Include("B.C")
         where b.Column1='column'


???
------解决方案--------------------
var dbquery=from b in dbquery.Include("A.B").Include("A.C")
           where b.Column1='column'
 
------解决方案--------------------
from b in dbquery.Include(x=>x.A.Select(y=>y.B.Where(z=>z.xxx=yyy)))
不知道行不行 你试试
Include(x=>)这种方法 要添加某个Dll或命名空间
可能是System.Data.Entity

http://stackoverflow.com/questions/5159621/ef-code-first-includex-x-properties-entity-a-1-many-association
------解决方案--------------------
            List<AllNewsGroups> AllNewsGroups = new List<AllNewsGroups>();
            List<AllNewsGroups2> AllNewsGroups2 = new List<ceshi.AllNewsGroups2>();
            AllNewsGroups2.Add(new AllNewsGroups2 { Name = "新浪科技" });
            AllNewsGroups2.Add(new AllNewsGroups2 { Name = "新浪科技" });
            AllNewsGroups2.Add(new AllNewsGroups2 { Name = "新浪科技" });
            AllNewsGroups2.Add(new AllNewsGroups2 { Name = "新浪科技" });


            AllNewsGroups.Add(new AllNewsGroups { Name = "1",AllNewsGroups2 = AllNewsGroups2 });


            AllNewsGroups.Select(m => (m.AllNewsGroups2.Where(t => t.Name == "新浪科技")).Count()>0);


 public class AllNewsGroups
    {
        public string Name{get;set;}
        public List<AllNewsGroups2> AllNewsGroups2 { get; set; }
    }

    public class AllNewsGroups2
    {
        public string Name { get; set; }
    }