使用 SQLite 的问题:内存:与 NHibernate [英] Problem using SQLite :memory: with NHibernate

查看:29
本文介绍了使用 SQLite 的问题:内存:与 NHibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 NHibernate 进行数据访问,有一段时间我一直没有使用 SQLite 进行本地集成测试.我一直在使用一个文件,但我想我会退出 :memory: 选项.当我启动任何集成测试时,数据库似乎已创建(NHibernate 吐出表创建 sql)但与数据库交互会导致错误.

I use NHibernate for my dataacess, and for awhile not I've been using SQLite for local integration tests. I've been using a file, but I thought I would out the :memory: option. When I fire up any of the integration tests, the database seems to be created (NHibernate spits out the table creation sql) but interfacting with the database causes an error.

有没有人让 NHibernate 使用内存数据库?甚至有可能吗?我使用的连接字符串是这样的:

Has anyone every gotten NHibernate working with an in memory database? Is it even possible? The connection string I'm using is this:

Data Source=:memory:;Version=3;New=True

推荐答案

SQLite 内存数据库只有在与它的连接保持打开时才存在.在 NHibernate 的单元测试中使用它:
1. 在测试开始时打开一个 ISession(可能在 [SetUp] 方法中).
2. 在您的 SchemaExport 调用中使用来自该会话的连接.
3. 在您的测试中使用相同的会话.
4. 在测试结束时关闭会话(可能在 [TearDown] 方法中).

A SQLite memory database only exists as long as the connection to it remains open. To use it in unit tests with NHibernate:
1. Open an ISession at the beginning of your test (maybe in a [SetUp] method).
2. Use the connection from that session in your SchemaExport call.
3. Use that same session in your tests.
4. Close the session at the end of your test (maybe in a [TearDown] method).

这篇关于使用 SQLite 的问题:内存:与 NHibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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