CompiledQuery和NoTracking [英] CompiledQuery and NoTracking
问题描述
此博客文章表明,LINQ to Entities查询的最快性能是使用编译查询和禁用对象跟踪:
http://blogs.msdn.com/adonet/archive/2008/02/11 /exploring-the-performance-of-the-ado-net-entity-framework-part-2.aspx
我目前正在使用编译查询,但我很难找到正确的语法来修改特定编译查询的合并选项,因为您永远不会引用ObjectQuery<>。这是一个编译查询示例:
This blog post indicates the fastest performance for a LINQ to Entities query is to use both Compiled Queries and to disable object tracking:
http://blogs.msdn.com/adonet/archive/2008/02/11/exploring-the-performance-of-the-ado-net-entity-framework-part-2.aspx
I'm currently using Compiled Queries, but I'm struggling to find the correct syntax to modify the merge options for a specific compiled query since you never have a reference to an ObjectQuery<>. Here's an example compiled query:
static readonly Func< FooEntities, string ,IQueryable< User>> _fooQuery = |
CompiledQuery.Compile< FooEntities, string ,IQueryable< User>>( |
(ctx,id) =>来自用户 ctx.UserSet.Include( " Bar" ) |
其中user.Id == id |
select user); |
static readonly Func<FooEntities, string, IQueryable<User>> _fooQuery = |
CompiledQuery.Compile<FooEntities, string, IQueryable<User>>( |
(ctx, id) => from user in ctx.UserSet.Include("Bar") |
where user.Id == id |
select user); |
推荐答案
您在实体集级别禁用跟踪。所以你可能会这样做吗
ctx.UserSet.MergeOption = MergeOption.NOTracking
fooQuery(ctx,parameter);
ctx.UserSet.MergeOption = MergeOption.AppendOnly
Zeeshan Hirani
Well you disable tracking at the entityset level. so u could potentially do it like this
ctx.UserSet.MergeOption = MergeOption.NOTracking
fooQuery(ctx,parameter);
ctx.UserSet.MergeOption = MergeOption.AppendOnly
Zeeshan Hirani
这篇关于CompiledQuery和NoTracking的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!