SimpleClient Add InsertOrUpdate

This commit is contained in:
sunkaixuan
2022-06-14 18:01:43 +08:00
parent 2e986c350d
commit 147b3b2751
2 changed files with 22 additions and 0 deletions

View File

@@ -36,6 +36,8 @@ namespace SqlSugar
T GetSingle(Expression<Func<T, bool>> whereExpression); T GetSingle(Expression<Func<T, bool>> whereExpression);
T GetFirst(Expression<Func<T, bool>> whereExpression); T GetFirst(Expression<Func<T, bool>> whereExpression);
bool Insert(T insertObj); bool Insert(T insertObj);
bool InsertOrUpdate(T data);
bool InsertOrUpdate(List<T> datas);
bool InsertRange(List<T> insertObjs); bool InsertRange(List<T> insertObjs);
bool InsertRange(T[] insertObjs); bool InsertRange(T[] insertObjs);
int InsertReturnIdentity(T insertObj); int InsertReturnIdentity(T insertObj);
@@ -69,6 +71,8 @@ namespace SqlSugar
Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression); Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression);
Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression); Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression);
Task<bool> InsertAsync(T insertObj); Task<bool> InsertAsync(T insertObj);
Task<bool> InsertOrUpdateAsync(T data);
Task<bool> InsertOrUpdateAsync(List<T> datas);
Task<bool> InsertRangeAsync(List<T> insertObjs); Task<bool> InsertRangeAsync(List<T> insertObjs);
Task<bool> InsertRangeAsync(T[] insertObjs); Task<bool> InsertRangeAsync(T[] insertObjs);
Task<int> InsertReturnIdentityAsync(T insertObj); Task<int> InsertReturnIdentityAsync(T insertObj);

View File

@@ -148,6 +148,16 @@ namespace SqlSugar
{ {
return this.Context.Insertable(insertObj).ExecuteCommand() > 0; return this.Context.Insertable(insertObj).ExecuteCommand() > 0;
} }
public virtual bool InsertOrUpdate(T data)
{
return this.Context.Storageable(data).ExecuteCommand() > 0;
}
public virtual bool InsertOrUpdate(List<T> datas)
{
return this.Context.Storageable(datas).ExecuteCommand() > 0;
}
public virtual int InsertReturnIdentity(T insertObj) public virtual int InsertReturnIdentity(T insertObj)
{ {
return this.Context.Insertable(insertObj).ExecuteReturnIdentity(); return this.Context.Insertable(insertObj).ExecuteReturnIdentity();
@@ -278,6 +288,14 @@ namespace SqlSugar
return Context.Queryable<T>().Where(whereExpression).CountAsync(); return Context.Queryable<T>().Where(whereExpression).CountAsync();
} }
public virtual async Task<bool> InsertOrUpdateAsync(T data)
{
return await this.Context.Storageable(data).ExecuteCommandAsync() > 0;
}
public virtual async Task<bool> InsertOrUpdateAsync(List<T> datas)
{
return await this.Context.Storageable(datas).ExecuteCommandAsync() > 0;
}
public virtual async Task<bool> InsertAsync(T insertObj) public virtual async Task<bool> InsertAsync(T insertObj)
{ {
return await this.Context.Insertable(insertObj).ExecuteCommandAsync() > 0; return await this.Context.Insertable(insertObj).ExecuteCommandAsync() > 0;