Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate add unmapped column in interceptor
    primarykey
    data
    text
    <p>I'm trying to save a mapped entity using NHibernate but my insert to the database fails because the underlying table has a column that does not allow nulls and IS NOT mapped in my domain object. The reason it isn't mapped is because the column in question supports a legacy application and has no relevance to my application - so I'd like to not pollute my entity with the legacy property.</p> <p>I know I could use a private field inside my class - but this still feels nasty to me. I've <a href="https://stackoverflow.com/questions/579885/unmapped-columns-in-nhibernate">read</a> that I can use an NHibernate interceptor and override the OnSave() method to add in the new column right before my entity is saved. This is proving difficult since I can't work out how to add an instance of Nhibernate.type.IType to the types parameter of my interceptor's OnSave.</p> <p>My Entity roughly looks like this:</p> <pre><code>public class Client { public virtual int Id { get; set; } public virtual int ParentId { get; set; } public virtual string Name { get; set; } public virtual string Phone { get; set; } public virtual string Email { get; set; } public virtual string Url { get; set; } } </code></pre> <p>And my interceptor</p> <pre><code> public class ClientInterceptor : EmptyInterceptor { public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types) { if (entity is Client) { /* manually add the COM_HOLD column to the Client entity */ List&lt;string&gt; pn_list = propertyNames.ToList(); pn_list.Add("COM_HOLD"); propertyNames = pn_list.ToArray(); List&lt;Object&gt; _state = state.ToList(); _state.Add(false); state = _state.ToArray(); //somehow add an IType to types param ?? } return base.OnSave(entity, id, state, propertyNames, types); } } </code></pre> <p>Does anyone have any ideas on how to do this properly?</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.
 

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