Getting Fluent NHibernate To Build Database tables

前端 未结 2 1638
野的像风
野的像风 2021-01-17 01:11

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 c

相关标签:
2条回答
  • 2021-01-17 01:42

    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.

    0 讨论(0)
  • 2021-01-17 01:51

    The FluentNhiberante SessionSource object exposes the CreateSchema.

    var sessionFactory = Fluently.Configure()...
    var sessionSource = new SessionSource(sessionFactory);
    sessionSource.BuildSchema()
    
    0 讨论(0)
提交回复
热议问题