C# 实体框架linq到实体代码速度慢,但在SQLServerManagementStudio中速度快
以下EF查询在代码中运行缓慢,但在SQLServerManagementStudio中运行快速。如何重写此EF语句以缩短执行时间C# 实体框架linq到实体代码速度慢,但在SQLServerManagementStudio中速度快,c#,entity-framework-6,linq-to-entities,C#,Entity Framework 6,Linq To Entities,以下EF查询在代码中运行缓慢,但在SQLServerManagementStudio中运行快速。如何重写此EF语句以缩短执行时间 Context.OfferQuotations .Include(x => x.OfferRevision) .Include(x => x.OfferRevision.OfferParameters) .Include(x => x.OfferRevision.OfferParameter
Context.OfferQuotations
.Include(x => x.OfferRevision)
.Include(x => x.OfferRevision.OfferParameters)
.Include(x => x.OfferRevision.OfferParameters.Select(a => a.CostOfFundings.Select(i => i.OfferCostOfFunding.TermRange)))
.Where(x => x.Id == quotationId);
我以前遇到过这个问题,所以我只打开了
LazyLoading
和ProxyCreating
this.Context.Configuration.LazyLoadingEnabled = true;
this.Context.Configuration.ProxyCreationEnabled = true;
我以前遇到过这个问题,所以我只打开了
LazyLoading
和ProxyCreating
this.Context.Configuration.LazyLoadingEnabled = true;
this.Context.Configuration.ProxyCreationEnabled = true;
关闭上下文的懒散加载选项。跟随这篇文章
然后尝试将您的查询转换为join,目前它正在子查询方式下工作。关闭上下文的lazyloading选项。跟随这篇文章
然后尝试将查询转换为join,当前它正在子查询方式下工作。请显示在Management Studio中运行的查询请显示在Management Studio中运行的查询