2

我有这个测试方法,“列表”方法有问题。我想使用几个类(都包含 IAdminDecimal)。在 QueryOver 上,我有这个错误: 类型“T”必须是引用类型才能将其用作泛型类型或方法“NHibernate.ISession.QueryOver()”中的参数“T”

using (var session = sessions.OpenSession())
{
    using (var tx = session.BeginTransaction())
    {
        CurrentSessionContext.Bind(session);

        AdministrationService service = new AdministrationService(session);
        service.List<AdminDelay>();

        tx.Commit();
    }
}

班上 :

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

1 回答 1

3

尝试:

public IList<T> List<T>() where T : class, IAdminDecimal
于 2011-06-16T08:17:26.113 回答