0

我有一个 lambda 'where' 查询,像这样查询 Order 表:

List<Order> returnedOrders = _session.Query<Script>()Where(s => s.orderId == orderIdParam).ToList();

我还想检查相关OrderDetails表中列的值。所以returnedOrders有一个集合OrderDetails,即returnedOrders.orderDetails

所以 SQL 查询看起来像:

Where OrderId = 12345 and Order.OrderDetail.CreatedDate = '01-Jan-2013'

任何人都可以帮我正确的语法吗?

4

2 回答 2

1

您可以在方法中使用逻辑 AND ( &&) Where

var date = new Date(2013,1,1);

List<Order> returnedOrders = 
    _session.Query<Script>()
            .Where(s => 
                s.orderId == orderIdParam && 
                s.OrderDetails.Any(d => d.CreatedDate == date))
            .ToList();

您也可以附加另一种Where方法。

var date = new Date(2013,1,1);

List<Order> returnedOrders = 
    _session.Query<Script>()
            .Where(s => s.orderId == orderIdParam)
            .Where(s => s.OrderDetails.Any(d => d.CreatedDate == date))
            .ToList();
于 2013-01-15T12:01:23.610 回答
0

既然您知道订单 ID,它似乎没用,但是像这样

from order in orders 
from detail in order.Details 
where 
    order.Id = orderId && 
    order.Id == detail.OrderId && 
    detail.CreateDate == createDate
select order
于 2013-01-15T12:02:51.027 回答