是否可以使用NHibernate创建数据库? [英] Is it possible to create a database using NHibernate?

查看:185
本文介绍了是否可以使用NHibernate创建数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用NHibernate与FluentNHibernate为我的DAL。我还使用 SchemaExport SchemaUpdate 创建和更新我的数据库模式。

I am using NHibernate with FluentNHibernate for my DAL. I am also using SchemaExport and SchemaUpdate to create and update my database schema.

我的问题是,模式操作都要求数据库在它们工作之前存在。我想以编程方式创建我的数据库并更新架构,因为可能有多个数据库,并且创建数据库不仅是一次性操作。

My problem is that the schema operations all require the database to exist before they will work. I want to programmatically create my database and update the schema as there may be multiple databases and the creating of the database is not only a once-off operation.

我知道我可以通过在与master数据库的连接上执行create database命令来手动执行此操作,但是考虑到我使用NHibernate来进行所有数据库交互,这种感觉是错误的。另外,我使用SQLite内存数据库进行我的单元测试,所以我写的任何sql将必须知道我使用哪个数据库。

I know I can do this manually by executing a create database command on a connection to the master database, but this feels wrong considering that I otherwise use NHibernate for all my database interactions. As an aside, I use a SQLite inmemory database for my unit tests so any sql I write will then have to know which database I'm using.

有任何方法要获得NHibernate为我创建我的数据库?

Is there any way to get NHibernate to create my database for me?

推荐答案

看看 RhinoCommons 。在Rhino.Commons.ForTesting下,在 UnitOfWorkTestContextDbStrategy.cs Ayende 做了一些常规工作,创建数据库。

Have a look at RhinoCommons. Under Rhino.Commons.ForTesting, in UnitOfWorkTestContextDbStrategy.cs, Ayende has done some routine there that creates databases.

这篇关于是否可以使用NHibernate创建数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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