22

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?

1 Answer 1

26

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Is there anyway to do it without clearing all current data?

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.