Nhibernate HQL在哪里查询 [英] Nhibernate HQL where IN query
问题描述
我试图返回一个SimpleQuery列表,该列表查询单个表并使用IN. 我可以使用它来工作
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扩展项目? 以下是使用上述库完成的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在哪里查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!