获取连贯NHibernate来建立数据库表 [英] Getting Fluent NHibernate To Build Database tables

查看:283
本文介绍了获取连贯NHibernate来建立数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个应用程序使用ASP.NET MVC2,功能NHibernate,StructureMap和PostgreSQL。我是一个新手,总当谈到功能NHibernate。我有一个设置从几个不同的来源去,但是当我建立和运行我的应用程序它并不在我的连接字符串创建数据库的数据库表。我在几个不同的文件code所以林不知道哪个code,我需要后,如果我应该张贴这一切的。如果有一个关键的检查,请让我知道还是让我知道后所有code。谢谢!

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!

推荐答案

您可以使用从NHibernate的核心的的SchemaExport 类到你的模式导出到一个数据库中。

You can use the SchemaExport class from NHibernate Core to export your schema to a database.

要执行的模式出口,使用功能NHibernate数据库配置API中的 ExposeConfiguration 方法。

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();

还有可用 SchemaUpdate工具类,它不删除并重新创建您的架构,但更新现有的架构。这是有用的,如果您想preserve在数据库中的数据。

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 SchemaUpdate工具 NHibernate.Tool.hbm2ddl 命名空间。

这篇关于获取连贯NHibernate来建立数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆