我是NHibernate的新手,并尝试让我的第一个应用程序使用NHibernate + SQLite - 在内存数据库中。
到目前为止,我做了以下,
的hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<reflection-optimizer use="true"/>
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
<property name="connection.connection_string">"Data Source=:memory:;Version=3;New=True;"</property>
<property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
<property name="connection.release_mode">on_close</property>
<property name="query.substitutions">true=1;false=0</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
Hibernate.cs
public NHibernate.ISessionFactory Hibernate()
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "hibernate.cfg.xml"));
cfg.AddAssembly(System.Reflection.Assembly.GetExecutingAssembly());
var sessionFactory = cfg.BuildSessionFactory();
return sessionFactory;
}
现在,当我调用Hibernate()函数时,以下行抛出异常,
var sessionFactory = cfg.BuildSessionFactory();
异常:System.ArgumentException:'数据源不能为空。使用:内存:打开内存数据库'
我已经尝试解决这个问题很长一段时间了,我尝试过不同的连接字符串,但我没有运气。任何建议/指导将不胜感激。
非常感谢。
我怀疑配置文件中的连接字符串属性的值应该有双引号。