I'm using the latest version of NHibernate and recompiled the JetDriver with this version in the .Net 3.5 framework. Everything seems to be setup fine, there just isn't any data returned. Here is my code, anyone see any problems? Also, anyone know where to find a working sample of nhibernate using Access, that would be very helpful.
EDIT: My project is using .Net 4.0 and running on Windows 7 32-bit.
EDIT2: I just realized that I can change the name of the class and tablename in the User.hbm.xml file or delete the file completely and the program doesn't give an error, something is not right here.
hibernate.cfg.xml:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.JetDriver.JetDialect, NHibernate.JetDriver</property>
<property name="connection.driver_class">NHibernate.JetDriver.JetDriver, NHibernate.JetDriver</property>
<property name="connection.connection_string">Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database11.accdb</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
</session-factory>
</hibernate-configuration>
User.cs:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NhibernateTest
{
class User
{
public int ID { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
}
}
User.hbm.xml:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NhibernateTest"
namespace="NhibernateTest">
<!-- more mapping info here -->
<class name="User" Table="User">
<id name="ID" />
<property name="firstName"/>
<property name="lastName"/>
</class>
</hibernate-mapping>
Form1.cs (testing a call to the database):
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Linq;
using NHibernate.Cfg;
namespace NhibernateTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(User).Assembly);
ISession db = cfg.BuildSessionFactory().OpenSession();
var test = db.Query<User>().ToList();
}
}
}