views:

80

answers:

2

Hey all, quick NHibernate question.

In my current project, we have a denormalized table that, for a given unique header record, will have one or more denormalized rows.

When the user is accessing a POCO representing the header and performs an update, I need this change to cascade down to all of the denormalized rows. For example, if the user changes field 'A' in the normalized header, I need all denormalized rows to now reflect the new value for field 'A'.

My current though is to just do a foreach in the normalized header on the property set, since I already have an IList representing the denormalized rows, but I was hoping for a more elegant solution that does not involve writing a foreach loop for each normalized field that needs to propagate down to the denormalized table.

FYI in the pure Sproc world, we'd just issue a second update command in a save sproc with an appropriate where clause - but we're also trying to move away from the sproc dependencies and perform most operations in c#

TIA

A: 

Thanks all for the answers above. I looked into the event listener as suggested, and it seemed a bit too heavy for what we were trying to accomplish.

Since we're using a repository pattern and the intent is to embed as much of this kind of behavior in the model, we ultimately went with embedding the cascading updates in the setters of the header object's properties. Since these kinds of cascades can be tough to test, etc. it lets us test everything in the model among the pocos without ever having to rely on a SQL trigger or NHibernate.

In short, when a header is updated in it's setter, I do a quick for-each for the list of detail objects, and also update any other denormalized pocos in the object tree, then drop this into the database with a simple saveorupdate with nHibernate.

-Bob

Bob Palmer