ef linq 多表查询条件问题
A 表是要查询的表 B表和C表是父子关系
我需要查询 A 表的所有字段数据
条件是 A表和D表联合查询 条件是 D表TypeNo等于传进来的TypeNo And A 表的 Count != (C表 Status = 0 的B子表集合(B子表RequisitionDetailId=A表ID)B表 Count字段统计和 加上 C表 Status = 1 的B子表集合(B子表RequisitionDetailId=A表ID)B表 Count字段统计和)
查询语句怎么写
A表是申购单明细 B表是采购单明细 C表是采购单
B表和A表有字段关联
简单的说就是 查询出没有采购完的申购单 我是通过判断采购单待审核的采购单明细Count字段总和加上采购单已审核的采购单明细Count字段总和 对应申购单A表的Count字段是否相等 列出未采购完的申购单
var tempRes = form b in B,c in C where b.PurchaseId = c.id and (c.Status==0 or c.Status == 1)
select b.count,b.RequisitionDetailId;
from a in A where a.Count !=(from t in tempRes where t. RequisitionDetailId = a.id select count(t.RequisitionDetailId))
select a;
var tempRes = form b in B,c in C where b.PurchaseId = c.id and (c.Status==0 or c.Status == 1)
select b.count,b.RequisitionDetailId;
from a in A where a.Count !=(from t in tempRes where t. RequisitionDetailId = a.id select count).Sum()
select a;
var t = from a1 in A
join a2 in (
from a in A
join b in B on a.ID equals b.RequisitionDetailId
join c in C on b.PurchaseID equals c.ID
where c.Status == 0 || c.Status == 1
group a by a.ID into temp
select new { aID = temp.Key, bcount = temp.Count() })
on a1.ID equals a2.aID where a1.Count != a2.bcount select a1;