在nHibernate的Criteria中编写子查询
我已经在 Criteria 中阅读了有关子查询的内容,但我仍然无法正确掌握它。在这里我举一个例子,如果有人可以帮助我使用子查询来编写它,那就太好了。
假设我们有一张桌子,
Employee{EmployeeId.(int),Name(string),Post(string),No_Of_years_working(int)}
现在我想要所有担任经理且工作时间不超过 10 年的员工。我知道我们可以在不使用子查询的情况下获得结果,但我想使用子查询只是为了了解它在条件中的工作原理。
那么,我如何使用子查询编写条件来获取这些员工。
I've read about subquery in Criteria, but I am still unable to grasp it properly. Here I am taking one example and if somebody can help me write that using subquery it will be great.
Lets say we have table
Employee{EmployeeId.(int),Name(string),Post(string),No_Of_years_working(int)}
Now I want all the employees who are Managers and working for less than 10 years. I know that we can get the result without using subqueries but I want to use subquery just to understand how it works in criteria.
So, how I can write Criteria using subquery to get those employees.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯 - 代码应该是这样的:
希望这会有所帮助。
Well - the code should be something like this:
Hope this helps.
当我发现这个问题时,我试图执行类似于 Bipul 的任务,所以我主要得到 bernhardrusch 的答案想法,但我意识到,如果不添加 Projections.projectionList 子查询将无法工作。所以我决定在最终版本中删除几行代码:
I was trying to perform something similar to Bipul's task, when I found this question, so I mainly got bernhardrusch's answer idea, but I've realized that without adding the Projections.projectionList the subquery do not work. So I've decided to drop a few lines of code with the final version: