I’m updating NHibernate version of a project and comes across a few errors.
NHibernate.ISession’ does not contain a definition for ‘Linq’
It seems session.Linq<T>() is gone. An answer on StackOverflow says I need to use session.Query<T>() instead.
session.Linq<T>() is for the contrib provider for NHibernate 2.x
session.Query<T>() is for the built-in provider in NHibernate 3.x
I used Entity Framework for my personal projects for a while but wanted to try NHibernate. Instead of NUnit, I tried MS Test this time.
First problem was that MS Test fails, complaining that hibernate.cfg.xml does not exist. It did not copy the file to MS Test out directory. Of course, I set “Copy to Output Directory” to “Copy always”. Thanks to NHibernate Getting Started Guide. It is copied to bin folder, but not to output folder. “System.IO.FileNotFoundException: Could not find file ‘…\TestResults\684 2010-04-29 09_42_19\Out\hibernate.cfg.xml’.. ” occurred each time I ran the test. Some say it is a bug in MS Test, and I agree.
In order to copy the file to the output, you need to use DeploymentItem attribute. Thanks to Stackoverflow post, “NHibernate and MS Test“.You can put the attribute at class level as well as method level. I put it on the test class.
public class Task_Test
Then I had this error message; “Could not create the driver from NHibernate.Driver.SQLiteDriver”
I use “System.Data.SQLite” from sqlite.phxsoftware.com.After a little bit of googling, I found out that the example configuration was using “NHibernate.Driver.SQLiteDriver” and it is for old Sqlite driver.
The connection.driver_class should be “NHibernate.Driver.SQLite20Driver” in order to use System.Data.SQLite.
The below is my config.
<?xml version="1.0" encoding="utf-8" ?>
<property name="connection.connection_string">data source=SprintManager.sqlite</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>