使用Nhibernate筛选通过汇总根返回的子集合 [英] Filter child collection returned with Aggregate Root using Nhibernate

查看:76
本文介绍了使用Nhibernate筛选通过汇总根返回的子集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用Nhibernate加载聚合根时,我正在尝试过滤聚合根的子集合.向客户加载所有已发货的订单.这可能吗?

I'm trying filter the child collection of an aggregate root when loading it with Nhibernate. Load a Customer with all their Orders that have been shipped. Is this possible?

推荐答案

好吧,您可以公开在地图中过滤的属性,如下所示:

Well, you can expose properties that are filtered in the map, like so:

<bag name="shippedOrders" ... where="Status == 'Shipped'" >
   <key column="CustomerId" />
   <one-to-many class="Order" />
</bag>

"where"属性是任意SQL.

The 'where' attribute is arbitrary SQL.

理论上,您可以具有客户",订单"和发货订单"这两个属性.但是,我应该说我还没有这样做,我想测试一下NH在这种情况下如何处理级联.无论如何,添加/删除新项目时必须小心,以确保它们已正确添加/删除到两个集合中.

Theoretically you could have two properties of Customer, Orders and ShippedOrders. However, I should say that I have not done this, and I would want to test how NH handles cascading in this case. In any case, you will have to take care when new items are added/removed that they are added/removed correctly to both collections.

您要执行此操作的事实使我们想知道Order是否是聚合根.从长远来看,这样做可能会减少麻烦:

The fact that you want to do this makes we wonder if Order is an aggregate root. It might be less trouble in the long run doing it like this:

orderRepository.GetOrders(int customerId, OrderStatus[] statuses)

这篇关于使用Nhibernate筛选通过汇总根返回的子集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆