In my Base repo I have this code which works fine:
abstract class BaseRepo <T> : IRepo <T>
{
private ISession _session;
public Entity GetById<Entity>(int Id)
{
return _session.Get<Entity>(Id);
}
// other methods
}
I want to add another method to return all rows for an object (entity). I want to do something like:
public IList<Entity> GetAll<Entity>()
{
return _session.CreateCriteria<Entity>().List<Entity>;
}
but I get an error saying:
The type 'Entity' must be a reference type in order to use it as parameter 'T' in the generic type or method 'NHibernate.ISession.CreateCriteria<T>()'
Here's my DAL design for reference: Should I use generics to simplify my DAL?