domain driven design - NHibernate persist object changes for approval -


i building application allows users make changes objects, changes have approved before made permanent. using nhibernate.

how handle sort of scenario using? there articles out there tackle issue?

i thinking of having 2 tables each object. 1 current state , 1 proposed state. having generic changerequest object specify delete/insert/update , subject wants changed. but, don't believe nhibernate allow have 2 different mappings same object.

the 2 options off top of head...

each object have approved flag or approved date. (this encapsulated in common base class.) either need composite key including approval column (not recommended - composite keys pain) or each object have business key in addition pk. mean 1 table per entity metadata columns in each table determine approved. (you decide whether keep changes or latest.)

the other option 2 separate tables each object. can using entity names, introduced in nh2.1. easiest show example. have 1 class definition:

public class foo {     public virtual int id { get; set; }     public virtual string name { get; set; } } 

we have 2 hbm.xml files. note entity-name attribute after class. creates 2 tables, foo1 , foo2. (you pick own names via table attribute.)

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="nhhacking" assembly="nhhacking">   <class name="foo" entity-name="foo1">     <id name="id">       <generator class="native" />     </id>     <property name="name"/>   </class> </hibernate-mapping>  <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="nhhacking" assembly="nhhacking">   <class name="foo" entity-name="foo2">     <id name="id">       <generator class="native" />     </id>     <property name="name"/>   </class> </hibernate-mapping> 

when save entities, provide entity-name operation:

var foo1 = new foo {name = "foo1"}; var foo2 = new foo {name = "foo2"}; session.save("foo1", foo1); session.save("foo2", foo2); 

this allows select table entity goes to. of course want encapsulate entity names in constants class. need specify entity name operations (session.get(), session.save(), session.update(), session.delete(), etc.)


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -