关于 Entity framework的查询
现有两个类如下
public class A_Build
{
public int ID { get; set; }
public string Name { get; set; }
public DBDeleted Deleted { get; set; }
public virtual ICollection<A_House> A_House { get; set; }
}
public class A_House
{
public int ID { get; set; }
public string Name { get; set; }
public DBDeleted Deleted { get; set; }
public virtual A_Build A_Build{ get; set; }
}
我想在查询时过滤Deleted =1的数据
var query = context.A_BuildInfo.Include("A_House").
Where(b=> b.Deleted == DBModel.DBDeleted.UnDeleted);
这句只能过滤A_Build,怎样才能连A_House也一起过滤呢?
用的code first --------------------编程问答-------------------- 你可以用join查询
where 过滤 --------------------编程问答-------------------- 描述的不太清楚,你是想查 house 还是 build ?
如果查 house 可以 where(h=>h.delete==false && h.build.delete==false).select(house) --------------------编程问答-------------------- var query = context.A_BuildInfo.Include("A_House").
Where(b=> b.Deleted == DBModel.DBDeleted.UnDeleted)
.Select(b => new { Build = b, A_House = b.A_House.Where(x => !x.Deleted) }); --------------------编程问答-------------------- var query = context.A_BuildInfo.Include("A_House").
Where(b=> b.Deleted == DBModel.DBDeleted.UnDeleted).Where(b=>b.A_House.Any(a=>a.Deleted==DBModel.DBDeleted.UnDeleted))
试试这个。
补充:.NET技术 , LINQ