2011-01-27 47 views
2

配置FluentNHibernate,FluentMappings.AddFromAssembly;這意味着

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

它有什麼作用?它是否會在從ClassMap派生的Product類的程序集中查找任何類?或者背後的邏輯是什麼?我可以將這個程序集的任何隨機類放在這裏,並期望它能找到這個程序集中的所有映射類嗎?

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(); 
    } 

回答

3

我一直以爲,當你使用AddFromAssemblyOf,流暢的將嘗試每個類映射在裝配。

因此,您只需要從包含您的ClassMap的程序集中添加一個類(任何一個)。

附加從fluent wiki

..它然後添加任何流利映射從 包含YourEntity

組裝
+1

也可以鏈在一起一個`凡()`方法之後,以指定班級必須符合的一些標準。 – 2011-01-27 10:59:40