c# - NHibernate: Default value for a property over a null column -
i'm working old database used other applications, can't modify structure. have nullable columns want map non nullable type. instance have nullable endvalidity column on database want map on non nullable datetime, and, if null, should datetime.maxvalue, or more simple example, nullable bit column must false if null.
i'm thinking writing custom user type (with parameters if possible), or there included in nhibernate it?
if solution write custom usertype, boolean case, can override fluentnhibernate conventions apply usertype booleans?
it depends on how want poco class act. firstly if load null value want null value re-saved or want session commit/flush update record new default null field. if want keep null value in db how detect poco object boolean value save ie booleans have true , false options / values bit class has options / values of null, 0 , 1?
if say: want have nullable bits boolean , not nullable boolean dataype in poco class , have class update db remove nulls 1 solution pretty quick without diving custom types have 2 properties 1 nullable , protected or internal , 1 property in interface ( without mapping ) basic logic - reasons of dependancy injects poco classes ideally have interface or two: eg
internal virtual bool? isactive {get;set;} public bool myinterface.isactive { get{ return isactive ?? false; } set{ isactive == value ?? false; }; }
this way logic contained in code if rules more complex/complicated or 1 nullable bit has default of false has default of true ( because of insane developer last century ) can more control transformations. require working interfaces instead of real poco classes, again isn't bad thing, depends on development model.
Comments
Post a Comment