title: .NET ORMs need virtual, and can't deal with sealed?
body: <p>I am just getting started with .NET ORMs, to the point where I haven't even decided between Entity Framework and NHibernate. But in both cases, I'm running into a problem in that they seem to want me to compromise the integrity of my domain model in various ways, especially on finer points of C# object design. This is one of several questions on the subject.</p>
  
  <hr>
  
  <p>There is <a href="http://www.artima.com/intv/nonvirtualP.html" rel="noreferrer">a reason <code>virtual</code> is not the default for methods in C#</a>. The objects in my domain model are not prepared to make promises about the behaviors of subclasses, except in very specific cases where I mark them as such. Put another way, for very few methods on my domain objects is it appropriate to add a hook for unspecified new functionality.</p>
  
  <p>Yet NHibernate wants me to make everything <code>virtual</code>, and Entity Framework wants me to make all entity references <code>virtual</code>. I realize why they need it (to create proxy objects), and I realize it's actually a legitimate use of inheritance and <code>virtual</code>---they actually <em>are</em> hooking in to my properties in order to add new functionality. But it grates on me that I have to annotate my domain model classes with something that is entirely about persistence, and not at all expressive of their actual contract to implementers and consumers.</p>
  
  <p>As a smaller issue, which I realize I probably cannot do anything about, often it is expressive to annotate my classes with <code>sealed</code> <a href="http://blogs.msdn.com/b/ericlippert/archive/2004/01/22/61803.aspx" rel="noreferrer">for all the usual reasons</a>. This is a bit less grating though, since omitting an annotation from my domain objects for the purpose of persistence seems less bad than adding one.</p>
  
  <hr>
  
  <p>It is frustrating that after several years reading books like <em>Effective C#</em> or blogs like those of Eric Lippert, which give great advice on how to design expressive and bulletproof C# objects, the need to use ORMs is making me throw much of that knowledge out of the window. I am hoping that someone here can point out where I am wrong, either in my grasp of their capabilities or in my thinking about domain modeling and the role of ORMs.</p>