mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 完善 DbUpdateVersionException IsVersion 行版本异常;
This commit is contained in:
@ -109,12 +109,12 @@ namespace FreeSql.Internal.CommonProvider
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void ValidateVersionAndThrow(int affrows)
|
||||
protected void ValidateVersionAndThrow(int affrows, string sql, DbParameter[] dbParms)
|
||||
{
|
||||
if (_table.VersionColumn != null && _source.Count > 0)
|
||||
{
|
||||
if (affrows != _source.Count)
|
||||
throw new Exception($"记录可能不存在,或者【行级乐观锁】版本过旧,更新数量{_source.Count},影响的行数{affrows}。");
|
||||
throw new DbUpdateVersionException($"记录可能不存在,或者【行级乐观锁】版本过旧,更新数量{_source.Count},影响的行数{affrows}。", _table, sql, dbParms, affrows, _source.Select(a => (object)a));
|
||||
foreach (var d in _source)
|
||||
_orm.SetEntityIncrByWithPropertyName(_table.Type, d, _table.VersionColumn.CsName, 1);
|
||||
}
|
||||
@ -299,7 +299,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
try
|
||||
{
|
||||
affrows = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(affrows);
|
||||
ValidateVersionAndThrow(affrows, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -168,7 +168,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
try
|
||||
{
|
||||
affrows = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(affrows);
|
||||
ValidateVersionAndThrow(affrows, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
50
FreeSql/Internal/Exception/DbUpdateVersionException.cs
Normal file
50
FreeSql/Internal/Exception/DbUpdateVersionException.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql.Internal
|
||||
{
|
||||
public class DbUpdateVersionException : Exception
|
||||
{
|
||||
public DbUpdateVersionException(string message, TableInfo table, string sql, DbParameter[] dbParms, int affrows, IEnumerable<object> source) :
|
||||
base(message)
|
||||
{
|
||||
this.Table = table;
|
||||
this.Sql = sql;
|
||||
this.DbParams = DbParams;
|
||||
this.Affrows = affrows;
|
||||
this.EntitySource = source;
|
||||
this.EntitySourceCount = source.Count();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新实体的元数据
|
||||
/// </summary>
|
||||
public TableInfo Table { get; }
|
||||
/// <summary>
|
||||
/// 执行更新的 SQL
|
||||
/// </summary>
|
||||
public string Sql { get; }
|
||||
/// <summary>
|
||||
/// 执行更新命令的参数
|
||||
/// </summary>
|
||||
public DbParameter[] DbParams { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 执行更新命令影响的行
|
||||
/// </summary>
|
||||
public int Affrows { get; }
|
||||
/// <summary>
|
||||
/// 更新的实体数量
|
||||
/// </summary>
|
||||
public int EntitySourceCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新的实体
|
||||
/// </summary>
|
||||
public IEnumerable<object> EntitySource { get; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user