场景:一条订单下面有多个订单细节,Where里想晒选订单细节里的条件:OrderDetails.ProductType==2,在LINQ中如何实现?
var list = from o in db.Orders.Include(o => o.OrderDetails)
where o.UserInfo.UserName == User.Identity.Name && o.OrderDetails[0].ProductType==2
orderby o.OrderId descending
select o;
这样写会出错:LINQ to Entities does not recognize the method
'Store.Models.OrderDetail get_Item(Int32)' method, and this method cannot
be translated into a store expression.
var list = from o in db.Orders.Include(o => o.OrderDetails)
where o.UserInfo.UserName == User.Identity.Name && o.OrderDetails.first().ProductType==2
orderby o.OrderId descending
select o;
这样的过滤,要的结果是什么?
1.是一个 Orders 集合,
2.还是 一个 OrderDetails集合,
3.还是 一个 Orders集合,但是 每个Orders里面自带的 OrderDetails导航是有数据的,数据要满足ProductType==2
是第三种
@红尘中迷茫:
sql 语句写出来看看 吧
先查询订单明细表的type=2的 订单主键,然后在查订单信息。说实话这数据表看起来设计的不怎么好。(我不清楚业务逻辑)我感觉类型应该放在订单表中,放在明显表中会数据重复
sql select * from order where id in(select parentid from orderdetail where type=2)
linq var a=select od from orderdetail where od.type==2 select od.parentid
var orderList=select o from order where a.Contains(o.id) select o
如果不对你把sql写一下我看看什么逻辑查的