【问题标题】:Dapper insert duplicate record does not throw errorDapper 插入重复记录不会抛出错误
【发布时间】:2017-05-13 22:41:56
【问题描述】:

当我尝试插入重复记录时,Dapper 没有捕获错误。但是,它会使用错误消息填充结果的第一条记录。例如。

try
{
   var result = Dapper.SqlMapper.Query(SCADConn, sql, d, null, true, 30, ct);
   return result;
}
catch (Exception e)
{
   throw (e);
}

当我运行上述代码时,结果变量包含一条计数为 1 行的记录,其中包含以下 DapperRow

{{DapperRow, ErrorNumber = '2601', ErrorSeverity = '14', ErrorState = '1', ErrorProcedure = 'OrganizationAdd', ErrorLine = '55', ErrorMessage = '无法在对象'dbo中插入重复的键行。具有唯一索引“IX_Organization_1”的组织。重复键值为(AAA Purchasing Pty (Ltd), 123123123123)。'}}

【问题讨论】:

  • 尴尬的错误。我返回了一条错误处理记录

标签: dapper


【解决方案1】:

多么愚蠢的错误。我在存储过程错误处理中返回了一条错误记录。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 2016-08-02
    • 2015-11-12
    • 2012-05-17
    • 2019-08-04
    • 2019-06-28
    相关资源
    最近更新 更多