[英]Entity framework with Include method
I have issue with Include Method , scenario as given 我对Include Method有问题,方案如给定
Table Warehouse has columns 表仓库有列
--some more columns -更多的专栏
Table WarehouselnkedEcorders 桌子仓库
Warehouse Model has following Code 仓库模型具有以下代码
public class Warehouse
{
public Warehouse()
{
this.WarehouselnkedEcorders = new List<WarehouselnkedEcorder>();
}
//Some stuff
public virtual ICollection<WarehouselnkedEcorder> WarehouselnkedEcorders
{ get; set; }
}
WarehouselnkedEcOrdeMap has following Code WarehouselnkedEcOrdeMap具有以下代码
// Relationships
this.HasOptional(t => t.Warehouse)
.WithMany(t => t.WarehouselnkedEcorders)
.HasForeignKey(d => d.warehouseUniqueId);
Query 询问
I need to retrive a list of warehouse entity with status=true. 我需要检索状态为true的仓库实体的列表。 I tried the following way,but could not get result.
我尝试了以下方法,但无法获得结果。 How can I do this?
我怎样才能做到这一点?
List<Warehouse> lstObjWarehouse = objWMSContext.Warehouses.Include("WarehouselnkedEcorders").Where(//o=>SomeCondition)
.Where(o => SomeCondition)
.Where(o => o.Deleted == false).ToList();
Here I need to compare value of status=true of each row of "WarehouselnkedEcorder" and it should return result. 在这里,我需要比较“ WarehouselnkedEcorder”每一行的status = true值,它应该返回结果。
Use Any in query: 在查询中使用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();
Fixed to match 1:many condition 固定为匹配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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.