Nhibernate HQL where IN 查询

发布于 2024-08-24 16:20:37 字数 472 浏览 2 评论 0原文

我试图返回一个查询单个表并使用 IN 的 SimpleQuery 列表。 我可以使用它来工作

return new List<Jobs>(
    ActiveRecordMediator<Jobs>.FindAll(Expression.In("ServiceId", ids))
);

但是这真的非常非常慢。所以我喜欢做这样的事情

SimpleQuery<Job> query = 
    new SimpleQuery<Job>(@"from Job as j where ? in (j.ServiceId)", ids);

return new List<Job>(query.Execute());

但是我无法让 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());

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.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转身泪倾城 2024-08-31 16:20:37

请在此处查看 NHibernate HQL 文档。

我从你的代码中猜测,你正在执行 HQL 查询以返回 id 列表中 job.ServiceID 的所有作业。

顺便说一句

IQuery q = s.CreateQuery("from Job as j where j.ServiceId in (:serviceIds)");
q.SetParameterList("serviceIds", ids); 

,您听说过 NHibernate Lambda Extensions 项目吗?
下面是使用上述库完成的 IN 查询的示例。作为使用 HQL 的替代方案,可能会很有趣。

DetachedCriteria after =
    DetachedCriteria.For<Person>()
        .Add(SqlExpression.In<Person>(p => p.Name, 
          new string[] { "name1", "name2", "name3" }));

Have a look at the NHibernate HQL documentation here.

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.

Maybe something along the lines,

IQuery q = s.CreateQuery("from Job as j where j.ServiceId in (:serviceIds)");
q.SetParameterList("serviceIds", ids); 

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" }));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文