iinterceptor - NHibernate add unmapped column in interceptor -


I am trying to save a map unit using NHibernate, but fails to insert me into the database because The built-in table does not allow tap in a column and is not mapped to my domain object. The reason it has not been mapped is because the column in question supports a legacy application and there is no relevance to my application - so I do not want to contaminate my unit with heritage property.

I know I can use a private area inside my class - but it still feels bad for me. I have this that I can use the NHibernate interceptor and my unit Before saving, I can override the OnSave () method to add to the new column. This is proving difficult because I will add an example of Nhibernate.Type.IType in the type parameter of my interceptor onswave, it can not work.

My unit looks almost like this:

Public class client {public virtual ID (Get; set;}; Public Virtual Ent 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;}}

And my interceptor

  public class client interceptor: EmptyInterceptor {bit Public override bool OnSave (Object unit, Object ID, Object [] State, String [] Property name, NHibernate.Type.Iype [] Type) {If (unit is client) {/ * Manually client entity * / list & lt Add the column COM_HOLD to the string & gt; Pn_list = propertyNames.ToList (); pn_list.Add ("COM_HOLD"); PropertyName = pn_list.ToArray (); List & gt; Object & gt; _state = state.ToList ); _state.Add (wrong); state = _state.ToArray (); // Add an ITIP to some type param ??} Return base. OnWave (unit, id, state, c Nnam, type); }}  

Anyone have any ideas on how to do it properly?

I can not say definitely because I have never really done such (like Stephen, I Also I like to add a personal property), but you can only NHibernate.Type.BooleanType to type array?

  list & lt; ITYPE & gt; TypeList = types.ToList (); TypeList.Add (new Boolean type ()); Type = type list. Toure ();  

edit

Yes, it seems that you are right; In the types, there is a internal constructor I found some excavation and found TypeFactory :

Applications of static methods and constants at NHibernate.NHibernateUtil For example, if the default ITIP is good enough, for example, TypeFactory should be used only when the string requires a length of 300 instead of 255. At this point, NHibernate.String does not get you the exact ITYpe. Instead use TypeFactory.GetString (300) and keep the local variable that holds the context of ITYpe.

It looks like what you want NHibernateUtil :

Provides access to completely NHibernate built-in parameters Examples of ITepe can be used to bind values ​​for queries, even a factory for new blobs and clubbs.

  typeList.Add (NHibernateUtil.Boolean);  

Comments