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

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

问题描述

我将 NHibernate 和 FluentNHibernate 用于我的 DAL.我还使用 SchemaExportSchemaUpdate 来创建和更新我的数据库架构.

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天全站免登陆