Helloo..

I'm attempting to add multiple mappings to a Session (SessionFactory).
It works.. but I may not be doing it correctly.

This is what I have tried:

var sessionFactory =
                
Fluently.Configure().Database(MsSqlConfiguration.MsSql2008.ConnectionString(x 
=> x.Is(connectionString)))
                    .Mappings(m => 
m.AutoMappings.Add(AutoMap.AssemblyOf<SubscriptionModel>(cfg).UseOverridesFromAssemblyOf<SubscriptionMappingOverride>()))
                    .Mappings(m => 
m.AutoMappings.Add(AutoMap.AssemblyOf<MemberModel>(cfg).UseOverridesFromAssemblyOf<MemberMappingOverride>()))
                    .Mappings(m => 
m.AutoMappings.Add(AutoMap.AssemblyOf<MemberSubscriptionModel>(cfg).UseOverridesFromAssemblyOf<MemberSubscriptionMappingOverride>()))
                    .Mappings(m => 
m.AutoMappings.Add(AutoMap.AssemblyOf<TestModel>(cfg).UseOverridesFromAssemblyOf<TestMappingOverride>()))
                    .BuildSessionFactory();


AND ALSO


            var sessionFactory =
                
Fluently.Configure().Database(MsSqlConfiguration.MsSql2008.ConnectionString(x 
=> x.Is(connectionString)))
                    .Mappings(m => m.AutoMappings
                        
.Add(AutoMap.AssemblyOf<TestModel>(cfg).UseOverridesFromAssemblyOf<TestMappingOverride>())
                        
.Add(AutoMap.AssemblyOf<SubscriptionModel>(cfg).UseOverridesFromAssemblyOf<SubscriptionMappingOverride>())
                        
.Add(AutoMap.AssemblyOf<MemberModel>(cfg).UseOverridesFromAssemblyOf<MemberMappingOverride>())
                        
.Add(AutoMap.AssemblyOf<MemberSubscriptionModel>(cfg).UseOverridesFromAssemblyOf<MemberSubscriptionMappingOverride>())
                        )
                        .BuildSessionFactory();


As I said, both solutions work, I can read the data etc... 


but the MappingOverrides and the ShouldMap method in my automapping 
configuration are all called 4 times for every mapping addition 

(so ShouldMap is called 16 times in total)


Am I doing this properly?

Should I be using 1 session factory for each Model?? (surely not)


Any advice would be greatly appreciated.



(My AutoMapping Configuration)

    public class NedDataConfiguration : DefaultAutomappingConfiguration
    {
        public static int calls = 0;
 
        public override bool ShouldMap(Type type)
        {
            calls++;
 
            return type.Namespace == "Ned.Data.Models";
        }
    }

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/fluent-nhibernate/-/tvj5kGpDqn0J.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to