If you create your model in C# first, and then want to create a database schema that matches that model, you can do this easily with Fluent NHibernate.
First, you need some sort of Data Access Initialization class.
You could use this to create your Session Factory for any app. Note that I’ve created a EntitiesToMapConfiguration class to limit the types that Fluent is interested in. I don’t want NHibernate to start looking for a DataAccessInitializer table.
I’ve done one extra thing that you don’t need if you just want to create sessions from the Session Factory: I’ve called FluentConfiguration.ExposeConfiguration to save the NhibernateConfiguration into a private variable. I have also created a public NhibernateConfiguration property that exposes this so that it can specifically be used by the following code to create the database schema:
I’ve wrapped the runner in an NUnit test, and used the ExplicitAttribute to prevent the test from running accidentally –…
View original post 21 more words