title: EntityRef and compiled LINQ plans
body: <p>Is there any way to force LINQ-2-SQL to compile and cache plans for <a href="http://msdn.microsoft.com/en-us/library/bb348960.aspx">EntityRef</a>.</p>
  
  <p>From internal profiling we are seeing a significant amount of CPU used to keep on recompiling plans. </p>
  
  <pre>
  System.Reflection.Emit.DynamicMethod.CreateDelegate
  System.Data.Linq.SqlClient.ObjectReaderCompiler.Compile
  System.Data.Linq.SqlClient.SqlProvider.GetReaderFactory
  System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Compile
  System.Data.Linq.CommonDataServices+DeferredSourceFactory`1.ExecuteKeyQuery
  System.Data.Linq.CommonDataServices+DeferredSourceFactory`1.Execute
  System.Linq.Enumerable.SingleOrDefault
  System.Data.Linq.EntityRef`1.get_Entity
  </pre>
  
  <p>I would prefer to use entity ref, but I guess if there is no choice we can hand code this. </p>