Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate database schema from NHibernate mapping

Is it possible to generate the database schema from the Nhibernate mappings DLL?

My requirements is for MySQL. If so, how do I do that? Are there tools/scripts for this? Open source/freeware tools?
Additionally, can I use these tools to insert/update datasets to the database?

like image 370
Quintin Par Avatar asked Aug 19 '09 11:08

Quintin Par


People also ask

What is the difference between NHibernate and fluent NHibernate?

Fluent NHibernate is another way of mapping or you can say it is an alternative to NHibernate's standard XML mapping files. Instead of writing XML (. hbm. xml files) documents.

What is NHibernate in C#?

NHibernate is a mature, open source object-relational mapper for the . NET framework. It's actively developed, fully featured and used in thousands of successful projects. Easily map regular C# or VB.NET object models designed in Visual Studio.


2 Answers

Have you tried using NHibernate's built-in schema generation tool?

var cfg = new NHibernate.Cfg.Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(AnEntityInYourMappingLib).Assembly);
new NHibernate.Tool.hbm2ddl.SchemaExport(cfg).Execute(false, true, false, false);
like image 88
AJ. Avatar answered Oct 30 '22 18:10

AJ.


I use this code :

public void CreateDatabaseSchemaFromMappingFiles()
{
    NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
    cfg.Configure();
    NHibernate.Tool.hbm2ddl.SchemaExport schema = new NHibernate.Tool.hbm2ddl.SchemaExport(cfg);
    schema.Create(false, true);
}
like image 34
Kris-I Avatar answered Oct 30 '22 17:10

Kris-I