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

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

问题描述

我使用NHibernate的我dataacess,并且一段时间没有我一直在使用SQLite本地集成测试。我一直在使用的文件,但我想我会出来的:内存:选项。当我火了任何集成测试,数据库似乎是创建(NHibernate的吐出来创建表的SQL),但与数据库interfacting导致错误。

有没有人得到的每NHibernate的内存数据库与工作?它甚至有可能?我使用的连接字符串是这样的:

 数据源=:内存:;版本= 3;新= TRUE


解决方案

一个SQLite的内存数据库只只要给它的连接保持打开状态存在。为了在单元测试中与NHibernate使用它:

1.打开一个ISession你的测试开始(也许在一个[设置]法)。

2.使用来自该会议的SchemaExport您电话的连接。

3.使用在测试同一个会话。

4.在您的测试结束时,关闭(也许在一个[TearDown中]法)会议。

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.

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

解决方案

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