I use the following convention: public class EnumConvention : IPropertyConvention { public bool Accept(IProperty target) { if( target.PropertyType.IsEnum ) { return true; } Type t = Nullable.GetUnderlyingType(target.PropertyType); return t != null && t.IsEnum; }
public void Apply(IProperty target) { if( Nullable.GetUnderlyingType(target.PropertyType) != null) { target.CustomTypeIs(target.PropertyType).Nullable(); } else { target.CustomTypeIs(target.PropertyType).Not.Nullable(); } } } -- Roelof. On Sat, Apr 25, 2009 at 9:26 PM, harrychou <harryc...@gmail.com> wrote: > > Now I understands it. For mapping enum, you 'hard-code' your type to > int, it will cause the object become dirty immediately. > > As explained in the following two posts: > > > http://graysmatter.codivation.com/CommentView,guid,6fe1a7c3-1245-45b8-98f1-e4b369dcded9.aspx > > http://blog.benhartonline.com/post/2008/10/09/NHibernate-objects-dirty-on-load-with-nothing-set-in-between.aspx > > In my case, I am migrating my mapping from HBM to FluentNHibernate. In > HBM, I can just ignore the type, and NHibernate will figure out the > base type of my enum for me (which is int) ... > > Now in FluentNhibernate, if I didn't set CustomTypeIs, I am forced to > map the column type of string .... which is not right ... > > Is there a way to work around this issue? > > > On Apr 24, 3:00 pm, harrychou <harryc...@gmail.com> wrote: > > I have a problem. Whenever I add a mapping with .CustomTypeIs(typeof > > (int)), NHiberate thinks my object is dirty and try to update the > > object for me. ... > > > > This is causing performance problem since FindAll call will cause > > massive update statements .... > > > > The reason I use .CustomTypeIs(typeof(int)) is that I want my enum to > > map to integer ... > > > > My mapping is like the following, whenever I uncommnet the last row > > (Map(x => x.ContractType).CustomTypeIs(typeof(int));) I didn't get > > the extra update statement. .... > > > > public ClientMap() > > { > > Id(x => x.ID, "ClientID").GeneratedBy.GuidComb(); > > Version(x => x.Version).SetAttribute("unsaved-value", > > "-1"); > > Map(x => x.LastUpdatedDateTime); > > Map(x => x.LastUpdatedUser); > > Map(x => x.CreatedDateTime); > > Map(x => x.CreatedUser); > > > > Map(x => x.SharePointID); > > Map(x => x.BMC_ID); > > > > Map(x => x.ClientName); > > Map(x => x.CompanyFullName); > > Map(x => x.AlternativeNames); > > Map(x => x.Acronym); > > HasMany(x => x._CompanyAddress).Cascade.AllDeleteOrphan(); > > Map(x => x.RenewalMonth); > > Map(x => x.Platform); > > Map(x => x.IsActive); > > Map(x => x.IsCareFirstConnectClient); > > Map(x => x.InfoBoxEmail); > > > > HasMany(x => > > x._ClientRoleAssignments).Cascade.AllDeleteOrphan(); > > > > HasMany(x => x._ClientContacts).Cascade.AllDeleteOrphan(); > > > > Map(x => x.ContractType).CustomTypeIs(typeof(int)); > > } > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to fluent-nhibernate@googlegroups.com To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---