mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 完善 DbUpdateVersionException IsVersion 行版本异常;
This commit is contained in:
parent
4ba6e087e1
commit
f0b09f468c
@ -26,7 +26,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
|
||||
<DocumentationFile>Volo.Abp.Dapper.FreeSqlExtensions.xml</DocumentationFile>
|
||||
<DocumentationFile>FreeSql.Extensions.AdoNet.xml</DocumentationFile>
|
||||
<WarningLevel>3</WarningLevel>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -527,14 +527,5 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -3237,6 +3237,36 @@
|
||||
<param name="type"></param>
|
||||
<returns>Dict:key=属性名,value=注释</returns>
|
||||
</member>
|
||||
<member name="P:FreeSql.Internal.DbUpdateVersionException.Table">
|
||||
<summary>
|
||||
更新实体的元数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Internal.DbUpdateVersionException.Sql">
|
||||
<summary>
|
||||
执行更新的 SQL
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Internal.DbUpdateVersionException.DbParams">
|
||||
<summary>
|
||||
执行更新命令的参数
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Internal.DbUpdateVersionException.Affrows">
|
||||
<summary>
|
||||
执行更新命令影响的行
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Internal.DbUpdateVersionException.EntitySourceCount">
|
||||
<summary>
|
||||
更新的实体数量
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Internal.DbUpdateVersionException.EntitySource">
|
||||
<summary>
|
||||
更新的实体
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.GlobalFilter.Apply``1(System.String,System.Linq.Expressions.Expression{System.Func{``0,System.Boolean}})">
|
||||
<summary>
|
||||
创建一个过滤器
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
@ -52,7 +52,7 @@ namespace FreeSql.MySql.Curd
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -133,7 +133,7 @@ namespace FreeSql.MySql.Curd
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ namespace FreeSql.Odbc.KingbaseES
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -150,7 +150,7 @@ namespace FreeSql.Odbc.KingbaseES
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ namespace FreeSql.Odbc.MySql
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -133,7 +133,7 @@ namespace FreeSql.Odbc.MySql
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -150,7 +150,7 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ namespace FreeSql.Odbc.SqlServer
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -134,7 +134,7 @@ namespace FreeSql.Odbc.SqlServer
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ namespace FreeSql.PostgreSQL.Curd
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -150,7 +150,7 @@ namespace FreeSql.PostgreSQL.Curd
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ namespace FreeSql.ShenTong.Curd
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -151,7 +151,7 @@ namespace FreeSql.ShenTong.Curd
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ namespace FreeSql.SqlServer.Curd
|
||||
try
|
||||
{
|
||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -135,7 +135,7 @@ namespace FreeSql.SqlServer.Curd
|
||||
try
|
||||
{
|
||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, dbParms);
|
||||
ValidateVersionAndThrow(ret.Count);
|
||||
ValidateVersionAndThrow(ret.Count, sql, dbParms);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user