Nhibernate HQL where IN 查询 [英] Nhibernate HQL where IN query
问题描述
我试图返回一个查询单个表并使用 IN 的 SimpleQuery 列表.我可以使用
Im trying to return a SimpleQuery list that queries a single table and uses IN. I can get this to work using
return new List<Jobs>(
ActiveRecordMediator<Jobs>.FindAll(Expression.In("ServiceId", ids))
);
然而,这真的真的很慢.所以我喜欢做这样的事情
However this is really really really slow. So id like to do something like this
SimpleQuery<Job> query =
new SimpleQuery<Job>(@"from Job as j where ? in (j.ServiceId)", ids);
return new List<Job>(query.Execute());
但是我无法让 SimpleQuery 工作.我找不到任何涵盖此内容的文档,希望有人能够提供帮助.
However I cant get the SimpleQuery to work. I cant find any documentation covering this and was hoping someone out there would be able to help.
谢谢
推荐答案
查看 NHibernate HQL 文档 这里.
Have a look at the NHibernate HQL documentation here.
我从您的代码中猜测,您正在执行 HQL 查询以返回 ID 列表中包含 job.ServiceID 的所有作业.
I'm guessing from your code, that you're after a HQL query to return all jobs where the job.ServiceID in a list of ids.
也许是类似的东西,
IQuery q = s.CreateQuery("from Job as j where j.ServiceId in (:serviceIds)");
q.SetParameterList("serviceIds", ids);
顺便说一句,您听说过 NHibernate Lambda Extensions 项目吗?下面是使用上述库完成的 IN 查询示例.作为使用 HQL 的替代方案,可能会很有趣.
BTW, have you heard of the NHibernate Lambda Extensions project? Below is an example of the IN query done using the the mentioned library. Might be something interesting to look at as an alternative to using HQL.
DetachedCriteria after =
DetachedCriteria.For<Person>()
.Add(SqlExpression.In<Person>(p => p.Name,
new string[] { "name1", "name2", "name3" }));
这篇关于Nhibernate HQL where IN 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!