开发者

Configuring Multiple Entities mapping in 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.FluentM开发者_运维百科appings.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.


You only need to provide one mapped class per assembly to AddFromAssembyOf<T> and all the class maps within that assembly will be loaded.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜