mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 增加 IFreeSql.InsertOrUpdate 方法 #316
This commit is contained in:
66
FreeSql/Interface/Curd/IInsertOrUpdate.cs
Normal file
66
FreeSql/Interface/Curd/IInsertOrUpdate.cs
Normal 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<object> 后使用本方法,指定实体类型
|
||||
/// </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
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user