Hi!
Im new to NHibernate and Im currently trying to map NHibernate against
a SQL Compact Edition database.. I think I got the connection to the
database itself to work..since there no longer gets thrown any
exceptions.. but once I try to call a method called .GetAll() that
should retrieves all the posts in the table, it simply retrieves
nothing at all..
So I kind of need some help with the debugging since Im quite unsure
about how the mapping should be done..
My database has the following structure:
--------------------------------------------
| UrlsNotToValidateWithLogin |
--------------------------------------------
| AbsolutePath | nvarchar(500) |
----------------------------------------------
| Id | bigint |
----------------------------------------------
Then the hibernate.cfg.xml looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="dialect">
NHibernate.Dialect.MsSqlCeDialect
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlServerCeDriver
</property>
<property name="connection.connection_string">
Data Source="|DataDirectory|\DogDb.sdf"
</property>
</session-factory>
</hibernate-configuration>
</configuration>
and the mapping between NHibernate and the table looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DOG.Core.Domain.Models.UrlsNotToValidateWithLogin,
DOG.Core" table="UrlsNotToValidateWithLogin" dynamic-update="true">
<id name="ID" column="Id" type="Int64">
<generator class="assigned"/>
</id>
<property name="AbsolutePath"></property>
</class>
</hibernate-mapping>
And finally my repository for UrlsNotToValidateWithLogin looks like
this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DOG.Core.Interfaces;
using DOG.Domain.Domain.Models;
using NHibernate;
using DOG.Core.Helpers;
using NHibernate.Criterion;
namespace DOG.Domain.Domain.Repositories
{
public class UrlsNotToValidateWithLoginRepository :
IRepository<UrlsNotToValidateWithLogin>
{
public void Save(UrlsNotToValidateWithLogin entity)
{
using (ISession session = NHibernateHelper.OpenSession())
{
using (ITransaction transaction =
session.BeginTransaction())
{
session.Save(entity);
transaction.Commit();
}
}
}
public void Update(UrlsNotToValidateWithLogin entity)
{
using (ISession session = NHibernateHelper.OpenSession())
{
using (ITransaction transaction =
session.BeginTransaction())
{
session.Update(entity);
transaction.Commit();
}
}
}
public void Delete(long id)
{
using (ISession session = NHibernateHelper.OpenSession())
{
using (ITransaction transaction =
session.BeginTransaction())
{
session.Delete(id);
transaction.Commit();
}
}
}
public UrlsNotToValidateWithLogin GetById(long id)
{
using (ISession session = NHibernateHelper.OpenSession())
return
session.CreateCriteria<UrlsNotToValidateWithLogin>().Add(Restrictions.Eq("Id",
id)).UniqueResult<UrlsNotToValidateWithLogin>();
}
public IList<UrlsNotToValidateWithLogin> GetAll()
{
using (ISession session = NHibernateHelper.OpenSession())
return
session.CreateCriteria<UrlsNotToValidateWithLogin>().List<UrlsNotToValidateWithLogin>();
}
}
}
Does anyone see whats wrong?
Thanks in advance!
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.