使用 NHibernate 急切加载子集合
我想加载根实体并立即加载它的所有子集合和聚合成员。
一直在尝试在 FluentNHibernate 中使用 SetFetchMode
,但由于我的深度为 3 个级别,所以我在子集合之一中得到了重复项。 不幸的是,DistinctRootEntityResultTransformer 只删除了根重复项。
return Session.CreateInvoiceBaseCriteria(query, archived)
.AddOrder(new Order(query.Order, query.OrderType == OrderType.ASC))
.SetFetchMode("States", FetchMode.Eager)
.SetFetchMode("Attestations", FetchMode.Eager)
.SetFetchMode("AttestationRequests", FetchMode.Eager)
.SetFetchMode("AttestationRequests.Reminders", FetchMode.Eager)
.SetResultTransformer(new DistinctRootEntityResultTransformer())
.List<Invoice>();
我可以使用多重查询或类似的东西来存档吗?
此外,这种方法不会导致数据库产生不必要的巨大结果集吗?
有什么建议么?
I want to load root entities and eager load all it's child collection and aggregate members.
Have been trying to use the SetFetchMode
in FluentNHibernate, but I am getting duplicates in one of the child collection since I have a depth of 3 levels. DistinctRootEntityResultTransformer
unfortunately only removes the root duplications.
return Session.CreateInvoiceBaseCriteria(query, archived)
.AddOrder(new Order(query.Order, query.OrderType == OrderType.ASC))
.SetFetchMode("States", FetchMode.Eager)
.SetFetchMode("Attestations", FetchMode.Eager)
.SetFetchMode("AttestationRequests", FetchMode.Eager)
.SetFetchMode("AttestationRequests.Reminders", FetchMode.Eager)
.SetResultTransformer(new DistinctRootEntityResultTransformer())
.List<Invoice>();
Could I use multi queries or something similar to archive this?
Furthermore, wouldn't this approach result in unnecessarily huge result sets from the database?
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
找到了解决方案,但它并不漂亮。 首先,我找到所有发票 ID,然后在多重查询中使用它们,最后通过 HashedSet 过滤结果。 由于项目数量较多,有时我无法使用正常的 Restriction.In 并被迫将其作为字符串发送。
有什么建议的调整吗?
Found a solution but it isn't pretty. First I go and find all the Invoice IDs, then I use them in the multiquery and then at the end filtering the results through a HashedSet. Because of the large number of items sometimes i couldn't use the normalt Restriction.In and was forced to send it as a string.
Any suggested tweaks?
回答你的问题:是的,它会产生巨大的结果集。
我建议:
To answer your question: yes, it results in huge resultsets.
I suggest to:
虽然它可能不完全是您正在寻找的内容,但我建议您查看这篇文章:
包含许多子集合的急切加载聚合
如果您浏览该网站的其余部分,您会发现更多讨论急切加载和其他很棒的 nHibernate 内容的帖子。
While it might not be exactly what you are looking for, I would recommend looking at this article:
Eager loading aggregate with many child collections
If you look around the rest of that site you will find even more posts that discuss eager loading and other great nHibernate stuff.