Environment: ASP.Net with NHIbernate2.2, with single session, started on HTTPBeginReuest.
Use Case: Post account data to Update action. Validate account and find errors, example, incorrect website url format. Need to show incorrect url on screen to user and show error message.
Actual implementation: Once the account object has been retrieved from the database via NHibernate Get, update properties from request object. Now validate the object and find some errors. Evict the account object and load the errors and account object into TempData.
Redirect from Update action to Edit action (the latter responsible for rendering the view). In the edit action I check if the TempData["account"] exists, if so, retrieve it from there since it contains all the url the user entered. Since I need to get some "child" objects from the account, need to perform a Merge of the account so the lazy loaded data can be retrieved. The show the data on the view, etc etc.
Issue: When executing the Merge on the account (from TempData["account"] get "Object is Immutable" error
Question: Is this the correct pattern for handling issues. And how can I fix the issue with getting the immutable error.
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Vert.CRM.Business" namespace="Vert.CRM.Business.Entities">
<class name="Vert.CRM.Business.EntityInterfaces.IAccount" table="Account" dynamic-update="true">
<id name="Id" column="Id" type="int" >
<generator class="native">
</generator>
</id>
<property name="Name" ><column name="Name" length="50" not-null="true" sql-type="varchar(50)" /></property>
<property column="Website" type="string" name="Website" />