在 FNH 中配置多个实体映射
我正在尝试在我的 FNH 配置 SessionManager 类中添加以下内容。 我有 20 多个实体要映射,它们都位于 Entities 文件夹下的同一个项目中。 IE。项目名称.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();
除了全部列出之外,是否有更好/更短的方法将它们添加到配置中? 我不想分离不同项目中的实体来创建新的程序集。 或者只映射到 1 个实体就可以了?
这是我使用 FNH 的第一个项目,整个项目非常新。 我什至不确定我是否走在正确的轨道上。
非常感谢您的建议。
I'm trying add the the followings in my FNH configuration SessionManager class.
I have 20+ Entities to map and they're all sitting in the same project under Entities folder. ie. ProjName.BusinessLogic.Entities
The mapping classes are under ProjName.BusinessLogic.Mappings
This FNHSessionManager.cs file is under 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();
Is there a better/shorter way to add them in the configuration other than list them all?
I don't want to separate the entities in different project to create a new assembly.
Or mapping to only 1 entity would do?
This is my first proj using FNH and very new with whole thing.
I'm not even sure if I'm on the right track.
Your advice would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需为每个程序集提供一个映射类到
AddFromAssembyOf
,该程序集中的所有类映射都会被加载。You only need to provide one mapped class per assembly to
AddFromAssembyOf<T>
and all the class maps within that assembly will be loaded.您无需将它们全部列出。流畅的配置映射设置可在程序集中使用所有约定。
Fluently.Configure() .Mappings(m => m.FluentMappings.AddFromAssembyOf
()).BuildSessionFactory();
(T) 可以是父程序集 ProjName.BusinessLogic 中的任何类。
Fluent 将从程序集 ProjName.BusinessLogic 配置映射。
You don't need to list them all. Fluent configuration mapping setup to use all conventions in an assembly.
Fluently.Configure() .Mappings(m => m.FluentMappings.AddFromAssembyOf
<T>
()).BuildSessionFactory();
(T) could be any class from you parent assembly ProjName.BusinessLogic.
Fluent will configure mapping from your assembly ProjName.BusinessLogic.