views:

19

answers:

2

Hi, 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 set 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.

A: 

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.

Diego Mijelshon
+1  A: 

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.

Jaguar

related questions