Getting Fluent NHibernate To Build Database tables

丶灬走出姿态 提交于 2019-12-01 14:00:36

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.

The FluentNhiberante SessionSource object exposes the CreateSchema.

var sessionFactory = Fluently.Configure()...
var sessionSource = new SessionSource(sessionFactory);
sessionSource.BuildSchema()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!