Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd Unmapped Data to NHibernate
    primarykey
    data
    text
    <p>I have an object I'm trying to persist to a legacy database with NHibernate. I have all of the relevant columns from a table mapped in my domain object, but have a few fields in the table that must be populated for the structure of the legacy db.</p> <p>Following a few recommendations, I created and registered an NHibernate interceptor to do this for me.</p> <pre><code> public class CustomLineItemInterceptor : EmptyInterceptor { public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types) { var lineItem = entity as SomeCustomLineItem; if (lineItem == null) return false; List&lt;string&gt; propertyNameList = propertyNames.ToList(); List&lt;IType&gt; typeList = types.ToList(); List&lt;object&gt; stateList = state.ToList(); propertyNameList.Add("Source"); // the unmapped column in the database typeList.Add(NHibernateUtil.String); stateList.Add("My Application's Name"); // the value I need to persist state = stateList.ToArray(); propertyNames = propertyNameList.ToArray(); types = typeList.ToArray(); return true; } } </code></pre> <p>I've looked at this <a href="https://stackoverflow.com/questions/824316/nhibernate-add-unmapped-column-in-interceptor">NHibernate add unmapped column in interceptor</a> and <a href="https://stackoverflow.com/questions/579885/unmapped-columns-in-nhibernate">Unmapped Columns in NHibernate?</a> without finding the answer.</p> <p>What I'm seeing is that I the OnSave method does fire, but I get nothing stored in the database (or the SQL query generated by NHibernate).</p> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload