﻿<?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>flukus commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>On a related note, how do you feel about using Automapper in this situation?
  
  
On a current project I keep changing my opinion. On one hand it moves the transform logic into it's own class. On the other hand it potentially creates performance problems like this.
  
  
At the moment I've settled on using automapper and cleaning up performance problems later. I hear you have a tool that can help this ;)
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment16</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment16</guid><pubDate>Wed, 16 Mar 2011 09:56:55 GMT</pubDate></item><item><title>Scooletz commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>@Dmitry
  
You can always write a query and name it. Then you have it reusable in cost of not knowing whats going on behind the curtain.
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment15</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment15</guid><pubDate>Tue, 15 Mar 2011 22:38:21 GMT</pubDate></item><item><title>Dmitry commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>They way I deal with this is by having the Find method return IQueryable&lt;T&gt; and specification objects (like the GetPostLastestForBoardById) that encapsulate Expression&lt;Func&lt;T, bool&gt;&gt;. This way Fetch could be applied on a per-specification basis.
  
  
My problem with using ICriteria/IQuery inside the controller is you cannot reuse queries anywhere else.
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment14</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment14</guid><pubDate>Tue, 15 Mar 2011 18:44:47 GMT</pubDate></item><item><title>John Farrell commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>@Chris 
  
  
" I don't mind having a repository supporting a hundred different queries, each of which is only used in one class"
  
  
So you enjoy having 100 classes be  dependent on a single class even though the each class uses 1% of the total functionality?  
  
  
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment13</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment13</guid><pubDate>Tue, 15 Mar 2011 17:31:38 GMT</pubDate></item><item><title>Chris Wright commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>I don't like having a controller create queries directly. I want to be able to test the query in isolation if it has any complexity. (I think I'd be okay with a controller using criteria for relatively simple queries; not entirely certain.)
  
  
So I have the *exact same code* as you would have here, except extracting the query into a method on the repository. I don't mind having a repository supporting a hundred different queries, each of which is only used in one class -- except then I'd probably find some way of splitting it up into separate classes for ease of maintenance. In practice, for a mid-size application, that ended up being between zero and eight queries per repository (but this application wasn't very database-centric).
  
  
We weren't considering the possibility of switching from nhibernate when doing this, but I suppose it keeps all the queries in one place, which should help when scoping the task.
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment12</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment12</guid><pubDate>Tue, 15 Mar 2011 17:26:01 GMT</pubDate></item><item><title>peter commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>a bit off-topic, but the header for this post is a day ahead (wednesday the 16th).
  
  
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment11</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment11</guid><pubDate>Tue, 15 Mar 2011 15:16:29 GMT</pubDate></item><item><title>Ayende Rahien commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>Jon,
  
Any switch would be a BIG undertaking, and you _can't_ abstract that.
  
It is just not possible.
  
  
Oh, and if you want to talk about document databases...
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment10</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment10</guid><pubDate>Tue, 15 Mar 2011 13:43:16 GMT</pubDate></item><item><title>Jon Wingfield commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>Ayende,
  
  
Thanks, that's a very interesting take and one that gives a huge advantage to NHibernate.  I'm used to thinking in ADO.NET terms.  
  
  
I have a few other concerns, though.  The first is separation of concerns.  I do think that Hibernate abstracts things away enough that typing:
  
  
_postRepository
  
        .FindAll(new GetPostLastestForBoardById(lastPostDateTime, boardId))
  
        .OrderBy(x=&gt;x.Id).ToList();
  
  
isn't much different than typing session.CreateCriteria
&lt;t()...  Either way, the controller now has to know HOW to get the data it needs as well as how to control the UI.  It just has to be determined if that additional responsibility will be worth the reduction in code.
  
  
My one other concern is that changing the database to a document-type database would require rewriting large portions of the app.  Sure, this doesn't happen on short (&lt;3 year projects), but I'm actually in the situation now where we COULD benefit from switching to a document database.  Problem is, we are too tightly coupled to the database implementation to do so (which would be the case here too, I believe).
&gt;</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment9</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment9</guid><pubDate>Tue, 15 Mar 2011 13:40:31 GMT</pubDate></item><item><title>Ayende Rahien commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>Jon,
  
[ayende.com/.../nhibernate-unit-testing.aspx](http://ayende.com/Blog/archive/2009/04/28/nhibernate-unit-testing.aspx)</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment8</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment8</guid><pubDate>Tue, 15 Mar 2011 13:27:56 GMT</pubDate></item><item><title>Jon wingfield commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>sorry I meant honest. typing on a phone sucks.
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment7</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment7</guid><pubDate>Tue, 15 Mar 2011 13:21:40 GMT</pubDate></item><item><title>Jon wingfield commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>How do you unit test a controller that directly uses ISession?  That's an host question.  Wouldn't mocking the session, criteria, etc. be cumbersome?
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment6</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment6</guid><pubDate>Tue, 15 Mar 2011 13:18:46 GMT</pubDate></item><item><title>zvolkov commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>In all the cases I've seen people adopting repository had no idea what they were doing. I would suggest somebody to live with repository for a year in production with moderately complex system (say, 10 times bigger than a blog engine) and see if they hold on to their opinion. When I was just learning NHibernate I started with repository and query objects before I realized that is not the right way to encapsulate logic in a cohesive way.
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment5</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment5</guid><pubDate>Tue, 15 Mar 2011 12:16:18 GMT</pubDate></item><item><title>Richard Dingwall commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>This problem has been present in pretty much every NHibernate application I've ever seen. 
  
  
@ Paulo's assumption is a dangerous one - using the repository pattern to hide a session forces you into sub-optimal scenarios, where you typically lose performance via either SELECT N+1 (slow), being forced to disable lazy loading (slow), not able to use NH features like fetching, or blossoming of hundreds of wrapper query objects/methods for each load scenario. Just use the session directly.
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment4</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment4</guid><pubDate>Tue, 15 Mar 2011 12:15:56 GMT</pubDate></item><item><title>Bas commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>Looking forward to your next post. I ran into this issue many times. 
  
I dont want to use fetch/thenfetch inside my repository methods because I dont need to fetch it everytime.
  
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment3</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment3</guid><pubDate>Tue, 15 Mar 2011 11:32:08 GMT</pubDate></item><item><title>Scooletz commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>@Paulo Quicoli
  
  
... or even better: the query object of type GetPostLastestForBoardById can have some Fetch applier, which shows which paths of relations should be considered during query, but
  
  
pure ISession is much easier to use though. I took this course in my latest code review of my colleagues' project and it _did_ work. The number of lines of code and the complexity were highly reduced.
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment2</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment2</guid><pubDate>Tue, 15 Mar 2011 10:44:32 GMT</pubDate></item><item><title>Paulo Quicoli commented on Reviewing OSS Project: Whiteboard Chat&amp;ndash;The Select N+1 issue</title><description>I don't see problem about adopting repositories. I want to believe they saw every time they need a post, they need also its owner.
  
So, maybe, in FindAll implementation they have a Fetch call for that relationship...
</description><link>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment1</link><guid>http://ayende.com/4783/reviewing-oss-project-whiteboard-chat-the-select-n-1-issue#comment1</guid><pubDate>Tue, 15 Mar 2011 10:35:49 GMT</pubDate></item></channel></rss>