NHibernate: How to set DynamicUpdate on all Entities?

旧街凉风 提交于 2019-12-24 05:59:17

问题


How can I set DynamicUpdate and DynamicInsert on all my entities?

It works perfectly when I put it together with my mapping code, but I would like to specify it only once for my entire project.

I could not find an option when creating the Session or in the Configuration.

Any ideas?


回答1:


I use fluent nhibernate so I would change them like this:

var fluentConfiguration = Fluently.Configure(NHibernate.Cfg.Configuration().Configure())
      .Mappings(m =>
          m.FluentMappings
          .AddFromAssemblyOf<OrderMap>()
          .Conventions.AddFromAssemblyOf<PascalCaseColumnNameConvention>())
          .ProxyFactoryFactory("NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernate");

var config = fluentConfiguration.BuildConfiguration();

foreach(PersistentClass persistentClass in config.ClassMappings)
{
    persistentClass.DynamicUpdate = true;
}

var sessionFactory = config.BuildSessionFactory();



回答2:


When using mapping-by-code its as simple as this:-

var mapper = new ModelMapper();

mapper.BeforeMapClass += (mi, t, map) =>
    {
        map.DynamicUpdate(true);
        map.DynamicInsert(true);
    };

...

Just make sure you remove it from ALL your class by class mappings as they will override this convention.

Just to complete if you do want to override any class definitions then you can also use

mapper.AfterMapClass += (mi, t, map) => { ... }


来源:https://stackoverflow.com/questions/19424897/nhibernate-how-to-set-dynamicupdate-on-all-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!