﻿<?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>Chen Kinnrot commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>Isn't it enough to call session.Load(userName) instead of loading all data about user for this case ?
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment14</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment14</guid><pubDate>Sat, 26 Mar 2011 23:07:49 GMT</pubDate></item><item><title>SteveR commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>@Christian
  
  
Unless there is no meaningful behaviour to model, then I'd dispute that what you describe qualifies as a domain model. If it doesn't embody the rules of the business domain then how can it be said to model it?
  
  
If all you want to do is bring back a bunch of dumb data containers and manipulate them procedurally then I don't see the point of using an ORM; something with much simpler capabilities would suffice. If you're not going to use OOP techniques to deal with the complexities and variability of the rules in your domain there's little point in manifesting that data in terms of classes.
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment13</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment13</guid><pubDate>Sat, 26 Mar 2011 19:29:07 GMT</pubDate></item><item><title>Christian Horsdal commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>@SteveR: IMO intelligent entities are much overrated. The domain model should contain stable domain stuff. Usually that turns out to be the basic form of the domain/data, not the behavior. So to me having dump or barely smart data in the data layer is usually a good thing.
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment12</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment12</guid><pubDate>Fri, 25 Mar 2011 15:41:31 GMT</pubDate></item><item><title>Brian Vallelunga commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>As Ayende pointed out, these types of scenarios are far too easy to build. I would also appreciate a post showing a more efficient way of performing the same logic, both NH specific and with more general patterns.
  
  
I have some code that is very similar to the ProductAttributes loop in the demo code using the Entity Framework 4. Since EF4 allows assigning foreign keys directly, I have simply created a cache of the IDs to dramatically reduce the DB hits. I'd be interested in seeing other options that solve the scenario of "if in the DB, assign, and if not, create and assign" pattern.
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment11</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment11</guid><pubDate>Thu, 24 Mar 2011 16:53:04 GMT</pubDate></item><item><title>Daniel commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>@Tim &amp; @Fred,
  
  
You fix it by using a combination of NHibernate Futures
  
[ayende.com/.../nhibernate-futures.aspx](http://ayende.com/Blog/archive/2009/04/27/nhibernate-futures.aspx)  
&amp;
  
using fetch in certain queries to avoid n+1 situations.
  
  
Also, it is very difficult to do both of these correctly with a repository structure like the application above because the repository structure makes it difficult to access these useful features by trying to hide NHibernate too much.
  
  
The point of these reviews is not to specifically fix this project's code, but to point out that it is very easy to write very nasty code with the conventional repository pattern used in this project.  I mean it takes 38 queries to process an order with 5 item where each item has 5 attributes. 
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment10</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment10</guid><pubDate>Thu, 24 Mar 2011 15:16:32 GMT</pubDate></item><item><title>SteveR commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>@Francois
  
  
Sure, but presumably some of those reasons don't apply in this case, for instance, having a wacky database schema that you can't control. Moreover, if NHibernate is just an implementation detail for a bunch of DAOs and the objects returned from them have their guts spilled out for a service class to go poking around in, what benefit are you deriving from, say, NHibernate's change tracking mechanisms? If the methods of your service class are just Transaction Script style procedures that go "I get this data, I change this data, I save this data and I'm done" then there's no need for anything to be tracking what's changed since the service method knows full-well what it's done.
  
  
I guess all I'm saying is that if people want to do things that way then they probably want something simpler than NHibernate.
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment9</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment9</guid><pubDate>Thu, 24 Mar 2011 14:52:19 GMT</pubDate></item><item><title>Ayende Rahien commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>Joe,
  
NH Prof is basically me, package in software that you can download.
  
I am running the standard set of code reviews on the codebase.
  
  
NH Prof does the same thing, but it doesn't require my presence.
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment8</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment8</guid><pubDate>Thu, 24 Mar 2011 14:51:10 GMT</pubDate></item><item><title>Bryan commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>The correct way is to buy UberProf and use it to make your data access queries better.  No, seriously!
  
  
All kidding aside, this is database-101 and ORMs-101 (select n+1).  That's what HQL FETCH is for, but I don't know how to do that with the new IQueryable queries being that I don't yet have the luxry of using them.
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment7</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment7</guid><pubDate>Thu, 24 Mar 2011 14:47:35 GMT</pubDate></item><item><title>joe commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>You should include a screenshot of the NH Prof warnings? Or are you finding these issues by browsing the source?
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment6</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment6</guid><pubDate>Thu, 24 Mar 2011 14:44:13 GMT</pubDate></item><item><title>Fred commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>@Tim, my thoughts exactly.
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment5</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment5</guid><pubDate>Thu, 24 Mar 2011 14:28:19 GMT</pubDate></item><item><title>Tim commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>These posts would be of so *much* more value if Ayende would post the "correct" way of doing it. Yes, we see the wrong way, now what is the right way?
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment4</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment4</guid><pubDate>Thu, 24 Mar 2011 14:24:21 GMT</pubDate></item><item><title>Alex Simkin commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>@Francois  - Why bother with NHibernate in this case? WebMatrix.Data by all means will be a better choice.
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment3</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment3</guid><pubDate>Thu, 24 Mar 2011 14:15:43 GMT</pubDate></item><item><title>Francois commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>@SteveR
  
  
A lot of people will use NHibernate simply to streamline data access and to abstract the complexities of a data model they may not have control over, as well as mapping the relational world to C#....and little more. The objects end up being DTOs and thats it, not entities in the OOP sense.
  
  
Then any kind of business logic, behavior, or process, is located in service classes.
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment2</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment2</guid><pubDate>Thu, 24 Mar 2011 13:38:31 GMT</pubDate></item><item><title>SteveR commented on The wages of sin: Hit that database one more time&amp;hellip;</title><description>Putting aside the inefficient database access for second, let me ask this: do the entities in this application actually encapsulate any meaningful behaviour whatsoever? And if not then what's the point of using an ORM to materialize stuff as an entities?
  
  
I'm seriously asking as I haven't looked at the application myself, but seeing even basic calculations performed outside of the entities raises a warning flag to me. It's possible that building all this fancy architecture in front of NHibernate makes people forget the purpose of using an ORM in the first place in addition to making the kind of mistakes you point out in your post much more likely.
</description><link>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment1</link><guid>http://ayende.com/4790/the-wages-of-sin-hit-that-database-one-more-time#comment1</guid><pubDate>Thu, 24 Mar 2011 11:24:23 GMT</pubDate></item></channel></rss>