实体框架4从包含标准参数变量的相当无害的linq查询生成SQL语句,但是对于每次连续的查询运行,数字参数后缀会不断递增。调用代码不以任何异步或事务方式运行。
这似乎只发生在我们的生产环境中,我无法在开发环境中复制它,其中每次调用此查询的代码都会生成参数@ p__linq__0和@ p__linq__1
样本linq:
var myJob =
(from job in this.context.Jobs
where job.Contract.ContractNo == contractNo && job.JobNo == jobNo
select job).FirstOrDefault();
生成示例sql查询:
SELECT ... WHERE ([Extent2].[ContractNo] = @p__linq__1799) AND ([Extent1].[JobNo] = @p__linq__1800) ) AS [Limit1]
SELECT ... WHERE ([Extent2].[ContractNo] = @p__linq__8262) AND ([Extent1].[JobNo] = @p__linq__8263) ) AS [Limit1]
SELECT ... WHERE ([Extent2].[ContractNo] = @p__linq__3590) AND ([Extent1].[JobNo] = @p__linq__3591) ) AS [Limit1]
SELECT ... WHERE ([Extent2].[ContractNo] = @p__linq__788) AND ([Extent1].[JobNo] = @p__linq__789) ) AS [Limit1]
SELECT ... WHERE ([Extent2].[ContractNo] = @p__linq__2250) AND ([Extent1].[JobNo] = @p__linq__2251) ) AS [Limit1]
我无法弄清楚为什么这些数字会增加,参数名称更改的问题在于它导致SQL Server为每个查询生成一个新的执行计划。