Fluent nhibernate 在FNH中配置多个实体映射

Fluent nhibernate 在FNH中配置多个实体映射,fluent-nhibernate,Fluent Nhibernate,我正在尝试在FNH配置SessionManager类中添加以下内容。 我有20多个实体要映射,它们都位于同一个项目的Entities文件夹下。即ProjName.BusinessLogic.Entities 映射类位于ProjName.BusinessLogic.Mappings下 此FNHSessionManager.cs文件位于ProjName.BusinessLogic.DAL下 var cfg = MsSqlConfiguration.MsSql2005

我正在尝试在FNH配置SessionManager类中添加以下内容。 我有20多个实体要映射,它们都位于同一个项目的Entities文件夹下。即ProjName.BusinessLogic.Entities 映射类位于ProjName.BusinessLogic.Mappings下 此FNHSessionManager.cs文件位于ProjName.BusinessLogic.DAL下

var cfg = MsSqlConfiguration.MsSql2005
                    .ConnectionString(c => c.FromAppSetting("connectionString"));

                isf = Fluently.Configure()
                    .Database(cfg)
                    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<User>())
                    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Provider>())
                    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Document>())
                    .BuildSessionFactory();
var cfg=MsSqlConfiguration.MsSql2005
.ConnectionString(c=>c.FromAppSetting(“ConnectionString”);
isf=fluntly.Configure()
.数据库(cfg)
.Mappings(m=>m.FluentMappings.AddFromAssemblyOf())
.Mappings(m=>m.FluentMappings.AddFromAssemblyOf())
.Mappings(m=>m.FluentMappings.AddFromAssemblyOf())
.BuildSessionFactory();
除了将它们全部列出之外,还有更好/更短的方法将它们添加到配置中吗? 我不想分离不同项目中的实体来创建新的部件。 或者只映射到一个实体就可以了

这是我的第一个项目使用FNH和非常新的整个事情。 我甚至不确定我是否在正确的轨道上


您的建议将不胜感激。

您只需为每个程序集提供一个映射类,将其添加到
AddFromAssembyOf
,该程序集中的所有类映射都将被加载。

您无需将它们全部列出。流畅的配置映射设置,以使用程序集中的所有约定

fluent.Configure().Mappings(m=>m.FluentMappings.AddFromAssembyOf
())
.BuildSessionFactory()

(T) 可以是父程序集ProjName.BusinessLogic中的任何类。 Fluent将从程序集ProjName.BusinessLogic配置映射。

Ref了解更多详细信息。