entity里面include的表添加where语句

xiaoyezijill 2013-01-06 05:03:04
我有三个表,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'
...全文
747 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
number1170196649 2013-05-04
  • 打赏
  • 举报
回复
也就是说A有多个B,C中也有多个B,也就是说A和B是多对多的关系?entities.A.Include("B.C").Where(a=>a.B.Any(b=>b.C.Column1=="……"))
City_member 2013-05-03
  • 打赏
  • 举报
回复
            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; }
    }
moonwrite 2013-04-26
  • 打赏
  • 举报
回复
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
EnForGrass 2013-04-26
  • 打赏
  • 举报
回复
var dbquery=from b in dbquery.Include("A.B").Include("A.C") where b.Column1='column'
xiaoyezijill 2013-01-06
  • 打赏
  • 举报
回复
高手啊!请教啊!
xiaoyezijill 2013-01-06
  • 打赏
  • 举报
回复
引用 2 楼 Chinajiyong 的回复:
var dbquery=from b in dbquery.Include("B.C") where b.Column1='column' ???
表结构如下: A表 ------- a B表 -------- a c C表 -------- c d 我希望加的where条件是C表中的d列 EnForGrass的写法和直接dbqurey=dbquery.where(...);是一样的,都会有错。主要是在entity里面有这样的关系: 假设A,B,C表对应的entity为A,B,C 1.A中有:Icollection<B> b{get;set;} 2.B中有:C c{get;set;} 有解决的方法吗?
EnForGrass 2013-01-06
  • 打赏
  • 举报
回复
var dbquery=from b in dbquery.Include("B.C") where b.Column1='column' ???
xiaoyezijill 2013-01-06
  • 打赏
  • 举报
回复
或者如何在A include B的时候加上一个B列的条件呢?

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧