title: NHibernate vs. EF 4.1+
body: <p>I am trying to decide the pros and cons of the 2 ORM primarily in this area.</p>
  
  <ol>
  <li>Compatibility with Sql Server 2008 R2 &amp; 2012.
  <ul>
  <li>This is very important as we simply don't have the resources to debug poor support of existing MS technology stack.</li>
  <li>Also planning ahead since 2012 is pretty much out and plans to migrate to it are in place.</li>
  </ul></li>
  <li>Support for .NET 4.0 and 4.5 (upcoming)
  <ul>
  <li>Again very important for pretty much the same reason above.</li>
  </ul></li>
  <li>Transaction handling and table hints eg. forcescan forceseek, read uncomitted.
  <ul>
  <li>A lot of times the query optimizer does its job well, other times I want the flexibility to tell it what to do.</li>
  </ul></li>
  <li>Support for conversation, self tracking attach &amp; detach
  <ul>
  <li>This is somewhat fundamental. I hate to keep the session open for prolonged period. Especially in distributed computing/web farm environment.</li>
  </ul></li>
  <li>Ability to handle code first development, create and update schema without destroying data.
  <ul>
  <li>EF 4.1 seems to be wanting in this regard, although 4.3 is leap and bound better. Also liking the data annotation better than seperate mapping classes in NH. Reason being I want to be able to send in the class and from there be able to create persistence model without widening the method for the mapping classes.</li>
  </ul></li>
  <li>Support for IRepository pattern</li>
  <li>Support for LINQ
  <ul>
  <li>Somewhat tied to (6) above I want really good support for linq. I don't want developers to muck around with lower level implementation and getting ourselves stuck to one particular ORM</li>
  </ul></li>
  <li>Performance</li>
  <li>Support for bulk CRUD operations, without having to load the data into the application layer. Eg. I want to increment all rows in a column of a particular table by 1. I don't want to load this up to memory, and increment the rows one by one. This would be crazy for such a simple operation. Linq2Sql used to have Magiq to handle this sort of thing, what does NH and EF have?</li>
  <li>Caching, eager loading, lazy loading, navigation properties.
  <ul>
  <li>Let me be frank I hate these things when done implicitly. Reason being it's hard to distinguish what is cached, stale from what is new. In EF I usually drop all navigation properties, because I don't want these properties loaded with top 5, because that's what the current operation needs, but further down the stream another developer attempts to do a count which will be inaccurate.</li>
  <li>So my personal policy - all SOA shall be stateless unless there is a good reason otherwise. If you need referencing data, get it from persistence. It will be slower but the code will be more readable and flexible.</li>
  <li>Similarly for caching. It is complex enough as it is in distributed environment, I want all caching to be very very explicit. If a developer wants to code against the cache, it should do so, not code against the ORM, and make it appear as if he is pulling fresh data from persistence when in fact he is getting stale data.</li>
  <li>Now question is, does NHibernate have any concept/abstraction that would make caching, eager/lazy loading so much more explicit than the one currently available in EF. In this case I don't care much about ease of development, I care more about clarity and explicitness.</li>
  </ul></li>
  </ol>
  
  <p>Also I don't care much for OSS vs. propietary argument. The team cannot afford the time to peek under the hood and start messing around with other people's code. I care more about the "it just works" angle than anything else.</p>