开发者

Configure FluentNHibernate, FluentMappings.AddFromAssembly; meaning

开发者 https://www.devze.com 2023-02-07 04:25 出处:网络
The line .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>() What does it do? Will it look for any class in the assembly of the P开发者_C百科roduct class that derives from the Cl

The line

    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>()

What does it do? Will it look for any class in the assembly of the P开发者_C百科roduct class that derives from the ClassMap ? Or what is the logic behind? Can I just put any random class of that assembly here and expect it to find all mapping classes in this assembly?

    private static ISessionFactory CreateSessionFactory()
    { 
          return Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2008
            .ConnectionString(Properties.Settings.Default.FnhDbString)
            .Cache(c => c
                .UseQueryCache()).ShowSql())
            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>()
            .Conventions.Add(FluentNHibernate.Conventions.Helpers.DefaultLazy.Never()))
            .BuildSessionFactory();
    }


I always thought that when you use AddFromAssemblyOf, fluent will try to map EVERY class in the assembly.

Therefore you just need to add a class (any one) from an assembly that contains your ClassMap.

Additional from the fluent wiki

..it then adds any fluent mappings from the assembly that contains YourEntity

0

精彩评论

暂无评论...
验证码 换一张
取 消