注册

【.Net驱动BUG】with语句中如果包含参数,则抛出异常“Parameter Index Out Of Range”

Alex 2022/05/13 2591 19

为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】: 8
【操作系统】:windows
【CPU】:x64
【问题描述】*:
多个with语句,中含有不同个数的参数则抛出异常“Parameter Index Out Of Range”.
SQL语句:

with Q as ( select BU_ID,OU_ID,count(0) CT from T_INSP K where K.DT > :p0 and K.DT < :p1 group by BU_ID,OU_ID ),Q2 as ( select BU_ID,OU_ID,count(0) CT from T_INSP K where K.DT > :p0 group by BU_ID,OU_ID ) select BU_ID,OU_ID,CT from Q union all select BU_ID,OU_ID,CT from Q2

C# 查询代码

using (Entities fs = new Entities()) { DateTime dt = new DateTime(2021, 1, 1); return fs.Database.SqlQuery<SummStatInfo>(sql, dt).ToArray(); }

错误堆栈:

System.IndexOutOfRangeException: Parameter Index Out Of Range 在 Dm.DmParameterCollection.CheckIndex(Int32 index) 在 Dm.DmParameterCollection.get_Item(Int32 index) 在 Dm.DmCommand.BindParameters(Int32& rowCount, DmDataReader rd, CommandBehavior behavior) 在 Dm.DmCommand.do_ExecuteDbDataReader(CommandBehavior behavior) 在 Dm.DmCommand.ExecuteDbDataReader(CommandBehavior behavior) 在 System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) 在 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<>c.<Reader>b__6_0(DbCommand t, DbCommandInterceptionContext`1 c) 在 System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) ...

经测试:
多个with语句中,参数个数相同则不报错。
不使用参数查询,则不会报错。
参数不在WITH语句中,也不会报错。

回答 0
暂无回答
扫一扫
联系客服