简体   繁体   English

NHibernate和拦截器在聚合根中

[英]NHibernate and Interceptor in aggregate root

Assuming that object A has a list of B objects, and B is linked to a C one. 假设对象A有一个B对象的列表,并且B被链接到一个C。

Using NHibernate, if I update as C instance, how can I be notified that "something" linked to one instance (and which instance) of A has been updated ? 使用NHibernate,如果我将其更新为C实例,如何通知与A的一个实例(和哪个实例)关联的“内容”已更新?

Using interceptor I know that C has been updated, but how to follow the way C -> B -> A automatically (C doesn't know B for instance, and C is not always aggregate root). 使用拦截器,我知道C已更新,但是如何自动遵循C-> B-> A的方式(例如,C不知道B,并且C并不总是聚合根)。

Depending on the specifics of your mapping, you can always search for the linked B entities every time an entity C is modified. 根据映射的具体情况,每次修改实体C时,您始终可以搜索链接的B实体。 Given that B is related to C by a foreign key relationship, you can search for all B (or the single B ), which has a foreign key equal to the C entity primary key. 假定B通过外键关系与C相关,则可以搜索具有等于C实体主键的外键的所有B (或单个B )。

If at the same time B does not know about A , you can use a similar procedure to notify which instance of A it is related to. 如果同时B不知道A ,则可以使用类似的过程来通知它与A哪个实例有关。 Or, if in the other hand B has a link to A , you can use that relationship instead. 或者,如果B另一方面具有到A的链接,则可以改用该关系。

The specific implementation would depend on how exactly are you mapping these entities together. 具体的实现方式取决于您将这些实体精确地映射在一起的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM