EntityRef和编译的LINQ计划

Sam*_*ron 6 c# linq linq-to-sql

有没有办法强制LINQ-2-SQL编译和缓存EntityRef的计划.

从内部分析中我们看到大量的CPU用于继续重新编译计划.

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

我更喜欢使用实体引用,但我想如果没有选择我们可以手动编码.

Sam*_*ron 4

不,没有办法强制 LINQ 2 SQL 编译和缓存 EntityRef 或 EntitySet 的查询。

它的实现中没有任何钩子。

如果您需要使用CompiledQuery,您将必须编写自己的包装器和帮助器。