SetFetchMode被忽略

时间:2011-12-14 18:42:59

标签: c# nhibernate

我有以下标准:

session.CreateCriteria<ItemDeliveryDetail>()
       .SetFetchMode("ItemDelivery", FetchMode.Eager)
       .Add(Restrictions.Eq("Id", 21932250))
       .List<ItemDeliveryDetail>();

这导致以下查询:

SELECT this_.itemdeliverydetail_id AS itemdeli1_4_0_,
       this_.itemdelivery_id       AS itemdeli2_4_0_,
       this_.partitiondate         AS partitio3_4_0_,
       this_.amount                AS amount4_0_,
       this_.processed_by_rem      AS processed5_4_0_,
       this_.single_item_price     AS single6_4_0_,
       this_.bookingaccount_id     AS bookinga7_4_0_,
       this_.supplierinvoice_id    AS supplier8_4_0_
FROM   itemdeliverydetail this_
WHERE  this_.itemdeliverydetail_id = :p0;

正如您所看到的,没有像我期望的那样加入ITEMDELIVERY的迹象。

如何解决?


ItemDelivery的映射如下所示:

mapping.CompositeId().KeyProperty(x => x.Id, "ITEMDELIVERY_ID")
                     .KeyProperty(x => x.DeliveryDate, "DELIVERY_DATE");
mapping.HasMany(x => x.ItemDeliveryDetails)
       .KeyColumns.Add("ITEMDELIVERY_ID", "PARTITIONDATE");

ItemDeliveryDetail的映射如下所示:

mapping.CompositeId().KeyProperty(x => x.Id, "ITEMDELIVERYDETAIL_ID")
                     .KeyReference(x => x.ItemDelivery, "ITEMDELIVERY_ID",
                                                        "PARTITIONDATE");

1 个答案:

答案 0 :(得分:2)

简短回答:不支持。

实际上,如果您明确禁用ItemDeliveryDetail.ItemDelivery的代理行为,则会出现导致(NHibernate内部)无限循环和导致堆栈溢出异常的情况。

编辑,长答案(部分发布在下面的评论中) ICriteria机制不支持对复合ID属性进行急切提取。我相信你可以使用HQL(通常HQL在获取声明和ICriteria上更强)。

可以在映射过程中照常禁用代理行为(可以是流畅的,也可以是xml或注释等)

我记得我尽我所能让它在NH2上工作(并且失败了),尽管我知道相关代码在NH3中没有得到改进/改变。

P.S。我4年来一直在NH工作。很好,因为它可能存在 gazillion 的事情。看看来源

相关问题