hi! people.I came accross the nhibernate library and wanted to give a try after succefully completed the great article from nhforge
http://nhforge.org/wikis/howtonh/your-first-nhibernate-based-application.aspx
i decided to give for my own a try on a real project with the version 2.1.0 irecently downloaded and with which i completed the tutorial.
after being through a lot of hussle i still can get up on my own running for three days now.i use even mygeneration to generate the mappings and classes for me.I know this post is long but i want to give all the details to help you help me ;)
so there are couples of tables in the database.on my test
Code:
private ISessionFactory _sessionFactory;
private readonly Configuration cfg = new Configuration();
[TestFixtureSetUp]
public void testfisturesetup()
{
cfg.Configure().AddAssembly(typeof(Currency).Assembly);
_sessionFactory = cfg.BuildSessionFactory();
}
[Test]
public void can_add_currency()
{
Currency c = new Currency();
c.Authorizer = "John";
c.Name = "Euro";
c.Comments ="No Comments";
c.Add(c);
using (ISession session = _sessionFactory.OpenSession())
{
Currency fromdb = session.Get<Currency>(c.CurrencyId);
Assert.IsNotNull(fromdb);
Assert.AreEqual(c.Name,fromdb.Name);
Assert.AreNotSame(c,fromdb);
Assert.AreEqual(c.Authorizer,fromdb.Authorizer);
Assert.AreEqual(c.Comments, fromdb.Comments);
}
}
i only target the class Currency mapping to the table currency (currency_id(identity)|name|authorizer|date_created(getdate())|comment)
Quote:
there is one hibernate.cfg.xml in the projects itself and one in the test project
and it's looking like
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="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=.;Initial Catalog=vouchman;Integrated Security=True</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
</session-factory>
</hibernate-configuration>
Quote:
the test failure for gives this reason:"Could not compile the mapping document Voucher.hbm.xml"
and on detail view i can read System.InvalidOperationException : Could not find the dialect in the configuration
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="vprovider" namespace="vprovider">
<class name="vprovider.Voucher" table="voucher">
<id name="VoucherId" column="voucher_id" type="Guid">
<generator class="guid.comb"/>
</id>
<property column="PIN" type="binary" name="Pin" not-null="true" />
<many-to-one name="BatchNo" column="batch_no" class="Batch" />
<property column="serial_no" type="Int32" name="SerialNo" not-null="true" />
<property column="date_created" type="DateTime" name="DateCreated" not-null="true" />
</class>
</hibernate-mapping>
What can be the things i'm obviously doing wrong?Please.Thanks for reading
Quote:
P.S: the type binary is mapped to the property of the type byte[] in the mapping class