0

How do I make NHibernate.Tool.hbm2ddl.SchemaExport to export certain classes in one database, and certain in another one? E.g. Person class should be mapped to a database with one connection string, and Product should be saved to a different database, so SchemaExport should create a Person table in one DB, and a Product table in the second one.

I defined NHibernate mappings for my classes, but I don't know where to specify the database/connection string for each class separately.

1 Answer 1

1

Mappings are Database independent, there is no way to define a connectionstring in them. Build up two configuration objects, one for each database and add all classes to appropriate configuration. Then use Schemaexport for each config.

var config1 = new Configuration()
    .AddClass(typeof(Person))
    .AddClass(typeof(Customer))
...

new SchemaExport(config1).Create(false, true);

var config2 = new Configuration()
    .AddClass(typeof(Product));

new SchemaExport(config2).Create(false, true);
Sign up to request clarification or add additional context in comments.

2 Comments

all classes to appropriate configuration - that's the part I am not sure how to do.
Many thanks! The AddClass method seems to be what I was looking for. I was using AddAssembly simply by inertia, from all the web examples, didn't even think I could have finer granulation using AddClass.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.