Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Database from NHibernate config files

Tags:

c#

nhibernate

Is it possible to generate the database tables and c# classes from NHibernate config files? Afterwards, is it possible to change the config files and update the tables and config files non-destructively?

Do you recommend any tools to do this? (preferably free...)

like image 413
NotDan Avatar asked Jan 11 '09 01:01

NotDan


People also ask

What is NHibernate in C#?

NHibernate is an actively developed, fully featured, open source object-relational mapper for the . NET framework. It is used in thousands of successful projects. It's built on top of ADO.NET and the current version is NHibernate 4.0.


2 Answers

As mentioned by Joachim, it's the "hbm2ddl.auto" setting that you're looking for.

You can set it by code like this:

var cfg = new NHibernate.Cfg.Configuration();
cfg.SetProperty("hbm2ddl.auto", "create");
cfg.Configure();

And you can also set it in your App.config file:

    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <property name="hbm2ddl.auto">create</property>
like image 183
Nikolaos Georgiou Avatar answered Oct 17 '22 21:10

Nikolaos Georgiou


check out the "hbm2ddl.auto" setting (in configuration or NHibernate.Cfg.Configuration ). with "create" you can recreate the whole database schema from your mappings and "update" setting should just update your schema.

like image 40
Joachim Kerschbaumer Avatar answered Oct 17 '22 21:10

Joachim Kerschbaumer