Not sure about why you aren't getting any data, but all your repository methods aren't using transactions. I would add that. I'd also change your getbyid method to use session.get instead of the criteria api.
for your data problems I would fire up sql profiler you look at the emitted sql. Personally I like the fluent mappings in fluent nhibernate or the loquacious mapping in 3.2 over xml files. Check out nhibernate cookbook. It will answer a lot of your questions. It also gives you nice implementations for a repository and base entity classes. On Aug 22, 2011 8:33 AM, "[email protected]" <[email protected]> wrote: > 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. > -- 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.
