我遇到包含方法问题,方案如给出
表仓库有列
- 更多列
表WarehouselnkedEcorders
仓库模型具有以下代码
public class Warehouse
{
public Warehouse()
{
this.WarehouselnkedEcorders = new List<WarehouselnkedEcorder>();
}
//Some stuff
public virtual ICollection<WarehouselnkedEcorder> WarehouselnkedEcorders
{ get; set; }
}
WarehouselnkedEcOrdeMap具有以下代码
// Relationships
this.HasOptional(t => t.Warehouse)
.WithMany(t => t.WarehouselnkedEcorders)
.HasForeignKey(d => d.warehouseUniqueId);
查询
我需要检索status = true的仓库实体列表。我尝试了以下方式,但无法获得结果。我怎么能这样做?
List<Warehouse> lstObjWarehouse = objWMSContext.Warehouses.Include("WarehouselnkedEcorders").Where(//o=>SomeCondition)
.Where(o => SomeCondition)
.Where(o => o.Deleted == false).ToList();
这里我需要比较“WarehouselnkedEcorder”每行的status = true值,它应该返回结果。
答案 0 :(得分:1)
在查询中使用Any:
List<Warehouse> lstObjWarehouse = db.Warehouses.Include("WarehouselnkedEcorder")
.Where(o => o.invoicePath == "SomeCondition"
&& o.Deleted == false
&& o.WarehouselnkedEcorders.Any(p => p.id == o.id
&& p.Deleted == false)).ToList();
答案 1 :(得分:0)
已修复以匹配1:多个条件
List<Warehouse> lstObjWarehouse = objWMSContext.Warehouses.Include("WarehouselnkedEcorder")
.Where(o => o.somefield == "SomeCondition"
&& o => o.Deleted == false
&& o=>o.WarehouselnkedEcorders.Where(dep=>dep.status==true)
.ToList();