Question

I need to set a property "DynamicUpdate();" for all entities in my project, but I don't want to duplicate the code in every classmaps, how do it?

An example of my classmaps now:

   public CStatMessagesVOMap()
        {
            DynamicUpdate();
            Table("TBCSTATMESSAGES");
            Id(x => x.Id);
            Map(x => x.Cstat).Not.Nullable();
            Map(x => x.Message).Length(500).Not.Nullable();
            Map(x => x.Allowed).Not.Nullable();
            References(x => x.DocumentKind).Column("DOCUMENTKIND").Cascade.None();
        }

 public DocumentKindVOMap()
        {
            DynamicUpdate();
            Table("TBDOCUMENTKIND");
            Id(x => x.DocumentKind).Column("DOCUMENTKIND");
            Map(x => x.Name).Length(20).Not.Nullable();
            Map(x => x.DocumentKind).CustomType<short>().Not.Nullable();
            HasMany(x => x.Messages).KeyColumn("DOCUMENTKIND").Inverse().Cascade.All();
        }
Was it helpful?

Solution

What you could do is to inherit your classes from AbstractMap<T> and this AbstractMap<T> inherits from ClassMap<T>, so on the constructor you could call the DynamicUpdate().

  public class AbstractMap<T> : ClassMap<T>
    {
        public AbstractMap()
        {
            DynamicUpdate();
        }
    }

 public class CStatMessagesVOMap : AbstractMap<CstatMessagesVO>
    {
        public CStatMessagesVOMap()
        {
            Table("TBCSTATMESSAGES");
            Id(x => x.Id);
            Map(x => x.Cstat).Not.Nullable();
            Map(x => x.Message).Length(500).Not.Nullable();
            Map(x => x.Allowed).Not.Nullable();
            References(x => x.DocumentKind).Column("DOCUMENTKIND").Cascade.None();
        }

In this case, all classes inherited from AbstractMap<T> would call the method you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top