开发者

How to set database schema for namespace in nhibernate

I have a database with multiple schemas: Security, Trade, etc. Each shema has multiple tables. Ie. Security schema has: Users, Roles etc..

Now, can I setup nhibernate so that the schema i bound to namespace. Ie. I have a security namespace in my project with the User and Role POCOs in it. So I wont to se开发者_JS百科t bind database schema to namespace. I know i can add Schema in maping file for each class, but if I have ie. 1000 class i must specify schema for each clas.

Please help.


you can do what you want programatically right before you create your sessionfactory like this:

var cfg = new Configuration().Configure();
foreach (var pc in cfg.ClassMappings)
{//just an example
     pc.Table.Schema = pc.MappedClass.Assembly.GetName().FullName.Substring(0, 3);
}
var sessionFactory = cfg.BuildSessionFactory();

note that normally you only build your session factory once so the performance impact (if any) happens only once.


NHibernate won't do it magically. If you want to avoid changing mapping files manually, use a code-based solution like ConfORM or FluentNHibernate instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜