NHibernate : QueryOver in generic method

て烟熏妆下的殇ゞ 提交于 2019-12-02 02:59:50

问题


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; }
}

回答1:


Try:

public IList<T> List<T>() where T : class, IAdminDecimal


来源:https://stackoverflow.com/questions/6368931/nhibernate-queryover-in-generic-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!