I have this test method, I have a problem on the "List" method. I'd like use several class (all inplement IAdminDecimal). On the QueryOver, I have this error : The type 'T' must be a reference type in order to use it as parameter 'T' in the generic type or method 'NHibernate.ISession.QueryOver()'
using (var session = sessions.OpenSession())
{
using (var tx = session.BeginTransaction())
{
CurrentSessionContext.Bind(session);
AdministrationService service = new AdministrationService(session);
service.List<AdminDelay>();
tx.Commit();
}
}
The class :
public class AdministrationService
{
private readonly ISession _session;
public AdministrationService(ISession session)
{
_session = session;
}
public IList<T> List<T>() where T : IAdminDecimal
{
var res = _session.QueryOver<T>().List<T>();
return res;
}
}
public interface IAdminDecimal
{
int Id { get; set; }
int Code { get; set; }
decimal Value { get; set; }
bool IsDeleted { get; set; }
}
public class AdminVAT : IAdminDecimal
{
public virtual int Id { get; set; }
public virtual int Code { get; set; }
public virtual decimal Value { get; set; }
public virtual bool IsDeleted { get; set; }
}
Try:
public IList<T> List<T>() where T : class, IAdminDecimal
来源:https://stackoverflow.com/questions/6368931/nhibernate-queryover-in-generic-method