Fluent NHibernate: Mixing Automapping and manual mapping

久未见 提交于 2019-12-22 04:45:12

问题


If using Fluent NHibernate, is it possible to automap most classes, but specify that a couple of particular classes should be mapped using the regular fluent API rather than being automapped? And if so, can anyone point me to some sample code that shows how to do it?

Thanks!


回答1:


It is possible and easy to mix-up mapping configurations:

var cfg = Fluently.Configure()
    .Database(configurer)
    .Mappings(map =>
                  {
                      // Automapping
                      map.AutoMappings.Add(AutoMap.Assemblies(Assembly.GetExecutingAssembly())
                                             .Where(type => type == typeof(Domain.Market.Share))
                                             .Where(type => type == typeof(Domain.HR.Employee)));

                      // Fluent mappings
                      map.FluentMappings.AddFromAssemblyOf<Domain.Client.Macys>();
                  });

Good luck. ;-)



来源:https://stackoverflow.com/questions/3530177/fluent-nhibernate-mixing-automapping-and-manual-mapping

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