Fluent NHibernate - Displaying Objects from Multiple Assemblies

Can objects from multiple assemblies be displayed in Fluent NHibernate?

I tried

AutoPersistenceModel
.MapEntitiesFromAssemblyOf<Class1>()
.AddEntityAssembly(assembly)

But it only loads objects from the assembly, not from the parent assembly of Class1.

EDIT. I understood. I had to upgrade Fluent NHibernate to version 1.0, where you can do it like this:

AutoMap
.AssemblyOf<Class1>()
.AddEntityAssembly(typeof(UserEntity).Assembly)
+3
source share
4 answers

I understood that. I had to upgrade Fluent NHibernate to version 1.0, where you can do it like this:

AutoMap
.AssemblyOf<Class1>()
.AddEntityAssembly(typeof(UserEntity).Assembly)
+4
source

NHibernate.Cfg.Configuration.AddAssembly() . . , , , "HibernatePersistenceAssembly", . , , NHibernate, , , , , .

AssemblyInfo.cs , NHibernate:

[assembly: HibernatePersistenceAssembly()]

Hibernate Utilities:

        public NHibernate.Cfg.Configuration ReloadConfiguration()
        {
            configuration = new NHibernate.Cfg.Configuration();
            configuration.Configure();
            ConfigureConnectionString();
            ConfigureAssemblies();

            return configuration;
        }

        private void ConfigureAssemblies()
        {
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (object attribute in assembly.GetCustomAttributes(true))
                {
                    if (attribute is HibernatePersistenceAssembly)
                        configuration.AddAssembly(assembly);
                }
            }
        }
+2

, AddEntityAssembly , .

, .

0
source

You can do something similar to what sharp does.

foreach (var assemblyName in mappingAssemblies)
{
    Assembly assembly = Assembly.Load(assemblyName);
    m.FluentMappings.AddFromAssembly(assembly );
}

It works for me at least.

0
source

Source: https://habr.com/ru/post/1719296/


All Articles