我想根据列表的内容查询一组结果,我已经设法为类Foo
的单个实例执行此操作,但我不确定如何执行此操作对于IList<Foo>
。
因此对于类Foo
的单个实例,这有效:
public ICriteria CreateCriteria(Foo foo)
{
return session
.CreateCriteria<Component>()
.CreateCriteria("Versions")
.CreateCriteria("PublishedEvents")
.Add(Restrictions.And(Restrictions.InsensitiveLike("Name", foo.Name, MatchMode.Anywhere),
Restrictions.InsensitiveLike("Type", foo.Type, MatchMode.Anywhere)))
.SetCacheable(true);
}
但是,当method参数是Foo
?
public ICriteria CreateCriteria(IList<Foo> foos)
{
return session
.CreateCriteria<Component>()
.CreateCriteria("Versions")
.CreateCriteria("PublishedEvents")
.Add(Restrictions.And(Restrictions.InsensitiveLike("Name", foo.Name, MatchMode.Anywhere),
Restrictions.InsensitiveLike("Type", foo.Type, MatchMode.Anywhere)))
.SetCacheable(true);
}
答案 0 :(得分:1)
如果您正在考虑要对此查询执行的操作,那么在您正在使用的构造中查询它实际上没有意义。您真正拥有的唯一选择是循环并动态创建标准,如下所示:
public ICriteria CreateCriteria(IList<Foo> foos)
{
var criteria = session
.CreateCriteria<Component>()
.CreateCriteria("Versions")
.CreateCriteria("PublishedEvents")
.SetCacheable(true);
foreach(var foo in foos)
{
criteria.Add(Restrictions.And(Restrictions.InsensitiveLike("Name", foo.Name, MatchMode.Anywhere),Restrictions.InsensitiveLike("Type", foo.Type, MatchMode.Anywhere)));
}
return criteria;
}