SqlParameter已经包含在另一个集合中 [英] The SqlParameter already contained by another collection
问题描述
大家好,
我有以下代码:
List<TallyBatchSession>[] sessions = new List<TallyBatchSession>[2];
SqlParameter BatchNumber = new SqlParameter("@BatchNo", SqlDbType.Int) { Value = batchNo };
var sessions1 = _siriusContext.CoreContext.ExecuteStoreQuery<TallyBatchSession>
(@"execute dbo.SiriusSP_GetTallyBatchSessions @BatchNo=@BatchNo", BatchNumber);
sessions[0] = sessions1.ToList();
var sessions2 = _siriusContext.CoreContext.ExecuteStoreQuery<TallyBatchSession>
(@"execute dbo.SiriusSP_GetTallyBatchSessionsByDate @BatchNo=@BatchNo", BatchNumber);
sessions[1] = sessions2.ToList();
return sessions;
第二个var session2从线程的标题中产生错误。我知道我可以再次创建相同的参数(命名不同)并在第二个语句中使用它。但是,我想知道是否有另一种解决方案可以解决这个问题,我可以以某种方式
重新使用该参数吗?
The second var session2 produces an error from the thread's title. I know I can create the same parameter again (named differently) and use it in the second statement. However, I'm wondering if there is another solution for this problem and can I somehow re-use that parameter?
提前致谢。
对于每一位专家,都有一位平等而相反的专家。 - Becker定律
我的博客
我的TechNet文章
推荐答案
您好Naomi,
Hi Naomi,
>>我想知道是否还有其他解决方案对于这个问题,我可以以某种方式重新使用该参数吗?
>>I'm wondering if there is another solution for this problem and can I somehow re-use that parameter?
根据以下文件,我们知道SqlParameter是可克隆的。
Based on the following document, we know that SqlParameter is clone-able.
请尝试以下代码。
List<TallyBatchSession>[] sessions = new List<TallyBatchSession>[2];
SqlParameter BatchNumber = new SqlParameter("@BatchNo", SqlDbType.Int) { Value = batchNo };
var sessions1 = _siriusContext.CoreContext.ExecuteStoreQuery<TallyBatchSession>
(@"execute dbo.SiriusSP_GetTallyBatchSessions @BatchNo=@BatchNo", BatchNumber);
sessions[0] = sessions1.ToList();
var sessions2 = _siriusContext.CoreContext.ExecuteStoreQuery<TallyBatchSession>
(@"execute dbo.SiriusSP_GetTallyBatchSessionsByDate @BatchNo=@BatchNo", ((ICloneable)BatchNumber).Clone());
sessions[1] = sessions2.ToList();
return sessions;
祝你好运,
张龙
这篇关于SqlParameter已经包含在另一个集合中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!