gpt4 book ai didi

c# - N休眠: QueryOver in generic method

转载 作者:行者123 更新时间:2023-11-30 22:37:46 25 4
gpt4 key购买 nike

我有这个测试方法,我在“列表”方法上有问题。我想使用几个类(全部用于 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();
}
}

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

最佳答案

尝试:

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

关于c# - N休眠: QueryOver in generic method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6368931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com