我正在尝试检索根聚合及其子集,对子集应用日期过滤器。
CREATE TABLE Shop
(
Id int
)
CREATE TABLE Order
(
ShopId int,
OrderDate datetime
)
自然,子对象没有 ShopId 属性来避免双向引用:
class Shop
{
int Id { get; set; }
List<Order> { get; set; }
}
class Order
{
DateTime OrderDate { get; set; }
}
FNHB 映射如下所示:
public ShopMap()
{
this.Table("SHOP");
this.Id(x => x.Id).Column("ID");
this.HasMany(x => x.Orders).Table("ORDER").KeyColumn("SHOP_ID");
}
public OrderMap()
{
this.Table("ORDER");
this.Map(x => x.OrderDate);
}
我正在尝试检索一个给定的商店,其订单放置在特定日期、给定参数之间shopId, fromDate, toDate
,我已经尝试过了,但它抛出了异常:
Session.Query<Shop>().Where(shop => shop.Id == shopId)
.FetchMany(
shop => shop.Orders.Where(
order => order .OrderDate >= fromDate && order.OrderDate <= toDate));
这可以在不使用魔术字符串(NHb 标准、HQL 等)的情况下实现吗,最好使用简单的 Linq 查询?