Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can NHibernate create tables from existing classes automatically?

Tags:

c#

nhibernate

I'm very new at this, but I need to create new tables from existing classes without creating them by hand. Can this be done using a tool or command line?

like image 833
mkelley33 Avatar asked May 02 '09 23:05

mkelley33


1 Answers

Yes, with nhibernate you can generate and update schemas automatically.

var cfg = new Configuration();  
cfg.Configure();  
cfg.AddAssembly(typeof (aClassFromYourProject).Assembly);  
new SchemaExport(cfg).Execute(false, true, false, false); 

Update: The overload options for SchemaExport.Execute have changed in the 3.x versions. The last argument is no longer needed.

new SchemaExport(cfg).Execute(true, true, false);
like image 133
Daniel Auger Avatar answered Oct 19 '22 19:10

Daniel Auger