开发者

Configure FluentNHibernate, FluentMappings.AddFromAssembly; meaning

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜