I'm using NHibernate with Fluent, and I'm trying to do a GetAll type thing using Critera.List
:
public static List<T> GetAll(int pageIndex, int pageSize)
{
using (ISession session = Utils.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
ICriteria criteria = session.CreateCriteria(typeof(T));
criteria.SetFirstResult(pageIndex * pageSize);
if (pageSize > 0)
{
criteria.SetMaxResults(pageSize);
}
return criteria.List<T>() as List<T>;
}
}
}
My map looks like this:
public class GenreMap: ClassMap<Genre>
{
public GenreMap()
{
Table("Genres");
Id(x => x.ID);
//.GeneratedBy.Identity();
Map(x => x.Name, "GenreName")
.Length(1000);
}
}
The underlying PK/ID is GenreID
(not ID), but I've set the map up correctly (or so开发者_如何学Go I believe).
So why am I getting that error?
You need to put the column name in for the ID in the map:
Id(x => x.ID, "GenreID");
Otherwise NHibernate will think the column name is the same as the property name, which it isn't in this case.
精彩评论