FluentNhibernate, add mappings from multiple assemblies

I tried adding the mapping classes manually using multiple calls to the .Mappings extension, but it seems to only include the latter. So, how do I add multiple selected class maps or multiple assemblies?

My current configuration is as follows:

 Return Fluently.Configure() _
                .Database(SQLiteConfiguration.Standard.ConnectionString(connectionString) _
                .Cache(Function(c) c.UseQueryCache())) _
            .Mappings(Function(m) m.FluentMappings.AddFromAssemblyOf(Of AccountMap)() _
                .Conventions.Add(FluentNHibernate.Conventions.Helpers.DefaultLazy.Never())) _
            .ExposeConfiguration(Function(c) InlineAssignHelper(cfg, c)) _
            .BuildSessionFactory()
+3
source share
2 answers

Just list all your builds.

m.FluentMappings
    .AddFromAssemblyOf(Of AccountMap)()
    .AddFromAssemblyOf(Of SomeOtherMap)();
+6
source

It seems that many people, including me, do not find a complete solution to add all the assemblies dumped to the bin folder if they are anonymous. In any case, I did it this way, it is not optimal, but its solution ..

Read more about NoEntity here.

    private static Conf CreateConfig()
    {
        return Fluently.Configure()
            .Database(DatabaseConfig)
            .Mappings(AddAssemblies)                
            .ExposeConfiguration(ValidateSchema)
            .ExposeConfiguration(BuildSchema)
            .BuildConfiguration();
    }

    private static void AddAssemblies(MappingConfiguration fmc)
    {
         (from a in AppDomain.CurrentDomain.GetAssemblies()
                select a
                    into assemblies
                    select assemblies)
                    .ToList()
                    .ForEach(a => 
                     {
                        //Maybe you need to inly include your NameSpace here.
                        //if(a.FullName.StartsWith("MyAssembly.Name")){
                        fmc.AutoMappings.Add(AutoMap.Assembly(a)
                            .OverrideAll(p => 
                            {
                                p.SkipProperty(typeof(NoEntity));
                            })
                            .Where(IsEntity));
                     }
          );
    }

    private static bool IsEntity(Type t)
    {
        return typeof(IEntity).IsAssignableFrom(t);
    }

    //Map IEntity
    public class User : IEntity{}
    public class UserMap : Entity<User>{}
    //UserMap inherits ClassMap<T>
+2

All Articles