开发者

NHibernate : QueryOver in generic method

开发者 https://www.devze.com 2023-03-13 19:55 出处:网络
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 :

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 开发者_如何学GoIsDeleted { get; set; }
}


Try:

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

精彩评论

暂无评论...
验证码 换一张
取 消