- 增加 IFreeSql.InsertOrUpdate 方法 #316

This commit is contained in:
28810
2020-05-21 01:59:35 +08:00
parent 4b7a49d88a
commit 6a443620e7
57 changed files with 4627 additions and 209 deletions

View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace FreeSql
{
public interface IInsertOrUpdate<T1> where T1 : class
{
/// <summary>
/// 指定事务对象
/// </summary>
/// <param name="transaction"></param>
/// <returns></returns>
IInsertOrUpdate<T1> WithTransaction(DbTransaction transaction);
/// <summary>
/// 指定事务对象
/// </summary>
/// <param name="connection"></param>
/// <returns></returns>
IInsertOrUpdate<T1> WithConnection(DbConnection connection);
/// <summary>
/// 添加或更新,设置实体
/// </summary>
/// <param name="source">实体</param>
/// <returns></returns>
IInsertOrUpdate<T1> SetSource(T1 source);
/// <summary>
/// 添加或更新,设置实体集合
/// </summary>
/// <param name="source">实体集合</param>
/// <returns></returns>
IInsertOrUpdate<T1> SetSource(IEnumerable<T1> source);
/// <summary>
/// 设置表名规则,可用于分库/分表参数1默认表名返回值新表名
/// </summary>
/// <param name="tableRule"></param>
/// <returns></returns>
IInsertOrUpdate<T1> AsTable(Func<string, string> tableRule);
/// <summary>
/// 动态Type在使用 Update&lt;object&gt; 后使用本方法,指定实体类型
/// </summary>
/// <param name="entityType"></param>
/// <returns></returns>
IInsertOrUpdate<T1> AsType(Type entityType);
/// <summary>
/// 返回即将执行的SQL语句
/// </summary>
/// <returns></returns>
string ToSql();
/// <summary>
/// 执行SQL语句返回影响的行数
/// </summary>
/// <returns></returns>
int ExecuteAffrows();
#if net40
#else
Task<int> ExecuteAffrowsAsync();
#endif
}
}

View File

@ -201,7 +201,7 @@ namespace FreeSql.Aop
/// </summary>
public DbParameter[] DbParms { get; }
}
public enum CurdType { Select, Delete, Update, Insert }
public enum CurdType { Select, Delete, Update, Insert, InsertOrUpdate }
public class CurdAfterEventArgs : CurdBeforeEventArgs
{
public CurdAfterEventArgs(CurdBeforeEventArgs before, Exception exception, object executeResult) :
@ -324,7 +324,7 @@ namespace FreeSql.Aop
private object _value;
public bool IsChanged { get; private set; }
}
public enum AuditValueType { Update, Insert }
public enum AuditValueType { Update, Insert, InsertOrUpdate }
#endregion
#region CommandBefore/After

View File

@ -44,6 +44,19 @@ public interface IFreeSql : IDisposable
/// <returns></returns>
IInsert<T1> Insert<T1>(IEnumerable<T1> source) where T1 : class;
/// <summary>
/// 插入或更新数据<para></para>
/// MySql: on duplicate key update<para></para>
/// PostgreSQL: on conflict do update<para></para>
/// SqlServer: merge into<para></para>
/// Oracle: merge into<para></para>
/// Sqlite: replace into<para></para>
/// Dameng: merge into<para></para>
/// </summary>
/// <typeparam name="T1"></typeparam>
/// <returns></returns>
IInsertOrUpdate<T1> InsertOrUpdate<T1>() where T1 : class;
/// <summary>
/// 修改数据
/// </summary>