﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Neal Blomfield commented on NH Prof Alerts: Select N + 1</title><description>Select N+1 also seems to be caused by specifying lazy = false for the collection in the mapping file.  I am guessing that NH2 defaults to using FetchMode.Select if you do not explicitly specify a fetch mode (I need to go read the docs / look at the code but commenting while I remember).
  
  
Might be worth adding something about this to the alert docs?
  
  
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment18</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment18</guid><pubDate>Fri, 09 Jan 2009 00:13:07 GMT</pubDate></item><item><title>Ayende Rahien commented on NH Prof Alerts: Select N + 1</title><description>[www.google.co.il/search?q=nhibernate+subselect](http://www.google.co.il/search?q=nhibernate+subselect)</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment17</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment17</guid><pubDate>Wed, 07 Jan 2009 11:21:49 GMT</pubDate></item><item><title>Henning commented on NH Prof Alerts: Select N + 1</title><description>OK - so I linked my little playground to the 2.0.1 GA ... so what do I do next :) I mean - how do I this subselect fetching?
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment16</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment16</guid><pubDate>Wed, 07 Jan 2009 11:18:40 GMT</pubDate></item><item><title>Ayende Rahien commented on NH Prof Alerts: Select N + 1</title><description>Yes, NH 1.2 doesn't have subselect fetching.
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment15</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment15</guid><pubDate>Wed, 07 Jan 2009 06:44:24 GMT</pubDate></item><item><title>Henning commented on NH Prof Alerts: Select N + 1</title><description>... ahh; does it matter that I'm still using NH 1.2? :)
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment14</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment14</guid><pubDate>Tue, 06 Jan 2009 21:38:39 GMT</pubDate></item><item><title>Henning commented on NH Prof Alerts: Select N + 1</title><description>maybe I'm missing your point :) what are you trying to tell me by mentioning the "sub select option" - I'm not sure.
  
  
I did a quick test: I have two orders, one with one orderitem, the otherone with two orderitems.
  
  
When I do the following:
  
  
DetachedCriteria criteria = DetachedCriteria.For(typeof (Order))                
  
                .SetFetchMode("OrderItems", FetchMode.Select);
  
  
            IList
&lt;order orders = criteria.GetExecutableCriteria(_sessionFactory.OpenSession()).List
&lt;order();
  
  
I get three SQL-statements (N+1 select!).
  
  
When I do the following instead:
  
  
DetachedCriteria criteria = DetachedCriteria.For(typeof (Order))                
  
                .SetFetchMode("OrderItems", FetchMode.Eager);
  
  
            IList
&lt;order orders = criteria.GetExecutableCriteria(_sessionFactory.OpenSession()).List
&lt;order();
  
  
I only get one statement, but each row contains the redundant order information.
  
  
I would like to get two statements: one for all orders and one for all orderitems, belonging to the previously fetched orders (in this case the orders are not restricted for simplicity).
&gt;</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment13</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment13</guid><pubDate>Tue, 06 Jan 2009 21:35:33 GMT</pubDate></item><item><title>Ayende Rahien commented on NH Prof Alerts: Select N + 1</title><description>Henning,
  
There are many options for eager loading with NH.
  
In this case, you are talking about the sub select option.
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment12</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment12</guid><pubDate>Sat, 03 Jan 2009 20:31:32 GMT</pubDate></item><item><title>Henning commented on NH Prof Alerts: Select N + 1</title><description>I might be mistaken, but if I do an eager load, doesn't that like join posts and comments? So when I have like a "bundle" of comments per post, I redundantly retrieve the post-data from the db :(
  
  
I would rather like two calls to the DB:
  
1. all the posts
  
2. get all the comments where the post-id is in the list of post-ids of the posts
  
  
This would reduce the DB-traffic as much as possible. But how would I do that *painless* with NH?
  
  
If I would have a methode like "GetAllWithComments()" this could first get all posts, and then issue a second query with a "in"-restriction or something. Or is there a better way?
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment11</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment11</guid><pubDate>Sat, 03 Jan 2009 13:57:41 GMT</pubDate></item><item><title>alberto commented on NH Prof Alerts: Select N + 1</title><description>1) Well, if you have N lazy loaded relations there are 2^N possible combinations (hence the method explosion) but you are probably right that in practice YAGNI all those.
  
2) But the consumers of the repository must now know which of the methods to call. Maybe I'm worrying to much, as it should be obvious (while "1" remains true) depending on what they want.
  
  
Thanks for the insight!
  
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment10</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment10</guid><pubDate>Tue, 30 Dec 2008 17:15:42 GMT</pubDate></item><item><title>Ayende Rahien commented on NH Prof Alerts: Select N + 1</title><description>1) Yes, it does. In practice, there are only a few ways of processing the graph.
  
2) There is a big difference, the only code that needs to know about this is the persistence code, not all the rest of the code, as is the case with EF.
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment9</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment9</guid><pubDate>Tue, 30 Dec 2008 16:27:18 GMT</pubDate></item><item><title>alberto commented on NH Prof Alerts: Select N + 1</title><description>My concerns with that solution are:
  
1) Does it really work in more complex, real world apps? Seems like it would lead to method explosion in the repository, polluting the API.
  
2) It doesn't seem a big difference from a PI point of view to the (openly criticized) "explicit lazy loading" in EF.
  
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment8</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment8</guid><pubDate>Tue, 30 Dec 2008 16:19:21 GMT</pubDate></item><item><title>Ayende Rahien commented on NH Prof Alerts: Select N + 1</title><description>Alberto,
  
You have GetAllWithComments(), or something like that
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment7</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment7</guid><pubDate>Tue, 30 Dec 2008 14:35:27 GMT</pubDate></item><item><title>alberto commented on NH Prof Alerts: Select N + 1</title><description>If you have a PostRepository and a GetAll() method that lazy loads Comments. Now you want run into this problem for some scenario. What do you do? 
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment6</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment6</guid><pubDate>Tue, 30 Dec 2008 13:15:51 GMT</pubDate></item><item><title>Ayende Rahien commented on NH Prof Alerts: Select N + 1</title><description>Alberto,
  
I don't follow you, can you explain further?
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment5</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment5</guid><pubDate>Mon, 29 Dec 2008 12:37:22 GMT</pubDate></item><item><title>alberto commented on NH Prof Alerts: Select N + 1</title><description>Indirectly related, I'm not so sure how people deal with this cases when you have a separate DAL (i.e Repositories), maybe a hint would be useful for your users too.
  
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment4</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment4</guid><pubDate>Mon, 29 Dec 2008 11:04:15 GMT</pubDate></item><item><title>Ayende Rahien commented on NH Prof Alerts: Select N + 1</title><description>Steve,
  
Thanks, I updated the docs &amp; the post.
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment3</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment3</guid><pubDate>Mon, 29 Dec 2008 05:57:40 GMT</pubDate></item><item><title>anonymous coward commented on NH Prof Alerts: Select N + 1</title><description>I believe a more common name for "Select N+1" is "N+1 selects" antipattern, I don't think there's anything bad in selecting a number N+1 from a database :)
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment2</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment2</guid><pubDate>Sun, 28 Dec 2008 21:57:35 GMT</pubDate></item><item><title>Steve Bohlen commented on NH Prof Alerts: Select N + 1</title><description>&gt;&gt;Select N+1 is a data access anti pattern, in which we are accessing the database in the least optimal way.
  
  
I think this should say 'non-optiimal' or 'sub-optimal' as I'm not 100% certain that I cannot think of an even less-optimal way to access the DB :D
  
  
&gt;&gt; which are also used to solved the issue of Too Many Queries.
  
  
Minor point, but I think '...solve the issue of...' is what's meant here (recognizing that english isn't your first language and its my ONLY (non-programming) language, so offering as helpful input, not criticism).
  
  
Looking (really) forward to this becoming a product I can buy~!
  
</description><link>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment1</link><guid>http://ayende.com/3774/nh-prof-alerts-select-n-1#comment1</guid><pubDate>Sun, 28 Dec 2008 20:27:09 GMT</pubDate></item></channel></rss>