【问题标题】:Reuse query SqlExpression cause System.ArgumentException The SqlParameter is already contained by another SqlParameterCollection重用查询 SqlExpression 导致 System.ArgumentException SqlParameter 已被另一个 SqlParameterCollection 包含
【发布时间】:2020-06-05 16:28:36
【问题描述】:

使用 OrmLite ServiceStack,我确实像这样查询 Select list 和 Count total:

public async Task<OrmInvoice> OrmTest(int Id)
    {
        var q = OrmDb.From<OrmInvoice>().Where(o => o.Id == Id);
        var rs1 = await OrmDb.SelectAsync(q);
        var rs2 = await OrmDb.CountAsync(q);

        var q2 = q.Clone(); //try to clone            
        var rs3 = await OrmDb.CountAsync(q2);

        return null;
    }

我只测试了 rs1 和 rs2 => 错误 尝试克隆,rs3 =>同样的错误

Caught System.ArgumentException

System.ArgumentException: The SqlParameter is already contained by another SqlParameterCollection.
  at System.Data.SqlClient.SqlParameterCollection.Validate
  at System.Data.SqlClient.SqlParameterCollection.Add
  at ServiceStack.OrmLite.OrmLiteReadCommandExtensions.SetParameters

我被卡住了,不知道为什么会出现这个问题,来自 ormlite 的基础?感谢您的帮助!

【问题讨论】:

  • 您解决了吗?今天早上我才开始使用 OrmLite

标签: ormlite-servicestack


【解决方案1】:

您应该在第二次查询之前清除参数。

【讨论】:

  • 我在 ormlite 服务堆栈中找不到任何 .Clear 或其他内容,以尝试解决此问题。你能给我一些研究 Clear 参数的关键吗?
猜你喜欢
  • 1970-01-01
  • 2017-10-17
  • 1970-01-01
  • 2011-12-11
  • 2011-09-11
  • 2012-06-14
  • 1970-01-01
  • 2019-04-10
  • 1970-01-01
相关资源
最近更新 更多