[英]NHibernate queryover generic type that extends a class
I'm working on a method that queries over a generic type and gets a list of that type. 我正在研究一种查询泛型类型并获取该类型列表的方法。 However, I want to be able to add
Where()
to this, so I want the query over to be able to query over any type that extends or implements a certain class/interface. 但是,我希望能够向其中添加
Where()
,所以我希望查询能够查询扩展或实现特定类/接口的任何类型。
public static List<T> getList<T>() where T : class
{
List<T> clientList = null;
using (ISession session =
NHibernateSessionFactoryManager.Factory.OpenSession())
{
clientList = new List<T>(session.QueryOver<T>()
//.Where(x => !x.IsDisabled) - won't work
//.Where(x => !x.IsDeleted) - won't work
.List());
}
return clientList;
}
I'd like something like this: 我想要这样的东西:
public static List<T:someClass> getList<T:someClass>() where T:someClass
{
List<T> clientList = null;
using (ISession session =
NHibernateSessionFactoryManager.Factory.OpenSession())
{
clientList = new List<T>(session.QueryOver<T>()
.Where(x => !x.IsDisabled)
.Where(x => !x.IsDeleted)
.List());
}
return clientList;
}
and someClass
and its children would have the IsDisabled, IsDeleted
fields so that queryOver doesn't complain about them. 并且
someClass
及其子级将具有IsDisabled, IsDeleted
字段,以便queryOver不会抱怨它们。
currently the method has red lines everywhere 目前该方法到处都有红线
如果对约束使用正确的语法,则看起来不错:
public static List<T> getList<T>() where T : someClass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.