开发者

NHibernate Lazy="Extra"

Is there a good explanation out there on what exactly lazy="extra" is capable of?

All the posts I've seen all just repeat the fact that it turns references to MyObject.ItsCollection.Count into select count(*) queries (assuming they're not loaded already).

I'd like to know if it's capable of more robust things, like turning MyObject.ItsCollection.Any(o => o.Whatever == 5) into a SELECT ...EXISTS query.

Section 18.1 of the docs only touches on it. I'm not an NH developer, so I can't really experiment with it and watch SQL Profiler without doing a bit of work getting everything set up; I'm just looking for some sort of reference describing what this feature is开发者_如何学编程 capable of.

Thank you!


for version 2.x it is only used to translate a collection.Count() into a select count and as far as i can see in the source, it will also allow the construct collection[5] to fetch that particular entity (with index 5) instead of hydrating the whole collection.

For version 3.x i didn't see anything related in the release notes


Just tried calling Any() on a Collection Customer.Orders mapped with lazy="extra"

customer.Orders.Any()

and the resulting SQL statement looked something like this (simplified):

SELECT *
FROM Order
WHERE CustomerId = 120

Whereas when calling

customer.Orders.Count > 0

the resulting SQL looked like this:

SELECT count(*)
FROM Order
WHERE CustomerId = 120


The lazy = extra allow to count the element of a collection without needing of fetching it, since the lazy entity is decorated with a proxy, when the client code ask for the .Count on the collection, a proper "select count" query is issued to the database. Without lazy=extra the collection is read from the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜