I am building an app with ASP.NET MVC2, Fluent NHibernate, StructureMap, and PostgreSQL. I am a total newbie when it comes to Fluent NHibernate. I got a setup going from a couple different sources but when I build and run my app it doesnt create the database tables for the database in my connection string. I have code in a few different files so Im not sure which code I need to post of if I should post all of it. If there is one key to check for please let me know or let me know to post all the code. Thanks!
Asked
Active
Viewed 3,948 times
2 Answers
7
You can use the SchemaExport
class from NHibernate Core to export your schema to a database.
To execute the schema export, use the ExposeConfiguration
method in the Fluent NHibernate database configuration API.
var sessionFactory = Fluently.Configure()
.Database(/* ... */)
.Mappings(/* ... */)
.ExposeConfiguration(cfg => new SchemaExport(cfg).Execute(true, true, false))
.BuildSessionFactory();
There's also a SchemaUpdate
class available which does not drop and recreate your schema but updates the existing schema. This is useful if you would like to preserve the data in the database.
SchemaExport
and SchemaUpdate
are available in the NHibernate.Tool.hbm2ddl
namespace.

Markus Dulghier
- 1,580
- 1
- 17
- 20
-
Ok that didnt work.. I probably have not gotten this set up right for MVC... Hmmm. Does anyon know of a link that outlines how exactly to set up for ASP.NET MVC app? – vt-cwalker Aug 10 '10 at 21:42
-
Take a look at Sharp Architecture (http://www.sharparchitecture.net/) and its Northwind Sample App. – Markus Dulghier Aug 11 '10 at 20:16
0
The FluentNhiberante SessionSource object exposes the CreateSchema.
var sessionFactory = Fluently.Configure()...
var sessionSource = new SessionSource(sessionFactory);
sessionSource.BuildSchema()

John Teague
- 657
- 5
- 11