Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EntityRef and compiled LINQ plans

Is there any way to force LINQ-2-SQL to compile and cache plans for EntityRef.

From internal profiling we are seeing a significant amount of CPU used to keep on recompiling plans.

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

I would prefer to use entity ref, but I guess if there is no choice we can hand code this.

like image 598
Sam Saffron Avatar asked Mar 21 '11 05:03

Sam Saffron


1 Answers

No, there is no way to force LINQ 2 SQL to compile and caches queries for EntityRef or EntitySet.

There are no hooks in the implementation for it.

If you need to use CompiledQuery you will have to write your own wrapper and helpers.

like image 88
Sam Saffron Avatar answered Oct 02 '22 06:10

Sam Saffron