查询主体必须以LINQ中的select子句或group子句结束

时间:2014-04-21 07:06:23

标签: sql linq

(from order in db.ProductOrder
 where (from cancel in db.OrderEvents
        where order.OrderId != cancel.OrderId && order.MemberId == MemberId)
 select order).ToList();

显示错误:

  

查询正文必须以select子句或group子句结束。

我该如何解决?

1 个答案:

答案 0 :(得分:1)

您不在子查询中选择任何内容

from cancel in db.OrderEvents
where order.OrderId != cancel.OrderId && order.MemberId == MemberId
// select something here

此外,您将此子查询的结果传递给where运算符,该运算符需要布尔结果。我假设你应该在这个子查询上调用Any()。类似的东西:

(from order in db.ProductOrder
 where (from cancel in db.OrderEvents
        where order.OrderId != cancel.OrderId
        select cancel).Any() && order.MemberId == MemberId
 select order).ToList()

在这种情况下,子查询的BTW lambda语法会更短:

db.OrderEvents.Any(oe => oe.OrderId != order.OrderId)