NHibernate Lambda 表达式 - 它们是否转换为 SQL
我是 NHibernate 的新手,我正在学习另一位开发人员编写的一些代码。我想了解 NHibernate 如何将基于 lambda 的条件转换为 SQL。
我知道在 Linq to SQL 中,在查询中使用 Lambda 表达式意味着整个事情会被 Linq to SQL 提供程序转换为表达式树,然后转换为 SQL(如果可能)。这可以通过 DataContext.Log = Console.Out 看到。
但是如果没有使用 Linq to NHibernate 的 NHibernate 标准表达式呢?
导入以下命名空间...
using NHibernate;
using NHibernate.Criterion;
using NHibernate.LambdaExtensions;
.. 标准代码如下所示...
return Session.CreateCriteria<MyObjectType>()
.Add<MyObjectType>(x => x.Id == id)
.UniqueResult<MyObjectType>();
是否会将其转换为 SQL 语句,例如
Select distinct * from table where id = [param]
... 或者将整个数据集拉入内存并给出一个 List,然后使用 lambda 表达式应用于对象。例如
return List<MyObject>.Where(x => x.id = id) [or something similar].
,我不确定我的导入 NHibernate.LambdaExtensions 是否提供了某种 SQL 转换。
I'm a bit of a NHibernate newbie and Im taking on some code written by another developer. I want to find out how NHibernate converts lambda based criteria into SQL.
I know in Linq to SQL using Lambda expressions on queries means that the whole thing is turned into an expression tree and then into SQL (where possible) by the Linq to SQL provider. This can be seen by doing DataContext.Log = Console.Out.
But what about an NHibernate criteria expression where Linq to NHibernate isnt being used?
The following namespaces are imported...
using NHibernate;
using NHibernate.Criterion;
using NHibernate.LambdaExtensions;
.. and the criteria code looks like this...
return Session.CreateCriteria<MyObjectType>()
.Add<MyObjectType>(x => x.Id == id)
.UniqueResult<MyObjectType>();
Will this be turned into an SQL statement e.g.
Select distinct * from table where id = [param]
... or will the whole dataset be pulled into memory giving a List and then have the lambda expressions applied against the objects. e.g.
return List<MyObject>.Where(x => x.id = id) [or something similar].
I', not sure if my importing NHibernate.LambdaExtensions provides a sort of translation into SQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它首先转换为 HQL 语句(启用日志记录并查看控制台中的语句),然后转换为 SQL 并发送到数据库。
它不会选择整个表进行内存和过滤。
It is turned to an HQL statement first (enable logging and look at the console for the statements) and then to an SQL and sent to the database.
It does not select the whole table to memory and filters there.