mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-29 01:47:06 +08:00
Add: Updateable.PageSize
This commit is contained in:
parent
2d253bcf78
commit
e4e53ba25c
@ -735,6 +735,9 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
Check.Exception(UpdateParameterIsNull == false, ErrorMessage.GetThrowMessage(" no support SetColumns and Where", "根据对像更新 db.Updateabe(对象) 禁止使用 SetColumns和Where ,你可以使用WhereColumns 和 UpdateColumns。 更新分为2种方式 1.根据表达式更新 2.根据实体或者集合更新 , 具体用法请查看文档 "));
|
Check.Exception(UpdateParameterIsNull == false, ErrorMessage.GetThrowMessage(" no support SetColumns and Where", "根据对像更新 db.Updateabe(对象) 禁止使用 SetColumns和Where ,你可以使用WhereColumns 和 UpdateColumns。 更新分为2种方式 1.根据表达式更新 2.根据实体或者集合更新 , 具体用法请查看文档 "));
|
||||||
}
|
}
|
||||||
|
private void ThrowUpdateByExpressionByMesage(string message)
|
||||||
|
{
|
||||||
|
Check.Exception(UpdateParameterIsNull == true, ErrorMessage.GetThrowMessage(" no support "+ message, "根据对像更新 db.Updateabe(对象) 禁止使用 SetColumns和Where ,你可以使用 "+ message + "。 更新分为2种方式 1.根据表达式更新 2.根据实体或者集合更新 , 具体用法请查看文档 "));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
public class UpdateablePage<T> where T:class,new()
|
||||||
|
{
|
||||||
|
public T[] DataList { get; set; }
|
||||||
|
public SqlSugarProvider Context { get; set; }
|
||||||
|
public int PageSize { get; internal set; }
|
||||||
|
public string TableName { get; internal set; }
|
||||||
|
public bool IsEnableDiffLogEvent { get; internal set; }
|
||||||
|
public DiffLogModel DiffModel { get; internal set; }
|
||||||
|
public List<string> UpdateColumns { get; internal set; }
|
||||||
|
public int ExecuteCommand()
|
||||||
|
{
|
||||||
|
if (DataList.Count() == 1 && DataList.First() == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (PageSize == 0) { PageSize = 1000; }
|
||||||
|
var result = 0;
|
||||||
|
var isNoTran = this.Context.Ado.IsNoTran();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
this.Context.Ado.BeginTran();
|
||||||
|
}
|
||||||
|
this.Context.Utilities.PageEach(DataList, PageSize, pageItem =>
|
||||||
|
{
|
||||||
|
result += this.Context.Updateable(pageItem).AS(TableName).EnableDiffLogEventIF(IsEnableDiffLogEvent, DiffModel).UpdateColumns(UpdateColumns.ToArray()).ExecuteCommand();
|
||||||
|
});
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
this.Context.Ado.CommitTran();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
this.Context.Ado.RollbackTran();
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public async Task<int> ExecuteCommandAsync()
|
||||||
|
{
|
||||||
|
if (DataList.Count() == 1 && DataList.First() == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (PageSize == 0) { PageSize = 1000; }
|
||||||
|
var result = 0;
|
||||||
|
var isNoTran = this.Context.Ado.IsNoTran();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
await this.Context.Ado.BeginTranAsync();
|
||||||
|
}
|
||||||
|
await this.Context.Utilities.PageEachAsync(DataList, PageSize, async pageItem =>
|
||||||
|
{
|
||||||
|
result += await this.Context.Updateable(pageItem).AS(TableName).EnableDiffLogEventIF(IsEnableDiffLogEvent, DiffModel).UpdateColumns(UpdateColumns.ToArray()).ExecuteCommandAsync();
|
||||||
|
});
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
await this.Context.Ado.CommitTranAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
if (isNoTran)
|
||||||
|
{
|
||||||
|
await this.Context.Ado.RollbackTranAsync();
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -173,6 +173,20 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Common
|
#region Common
|
||||||
|
public UpdateablePage<T> PageSize(int pageSize)
|
||||||
|
{
|
||||||
|
ThrowUpdateByExpressionByMesage(" PageSize(num) ");
|
||||||
|
UpdateablePage<T> result = new UpdateablePage<T>();
|
||||||
|
result.PageSize = pageSize;
|
||||||
|
result.Context = this.Context;
|
||||||
|
result.DataList = this.UpdateObjs;
|
||||||
|
result.TableName = this.UpdateBuilder.TableName;
|
||||||
|
result.IsEnableDiffLogEvent = this.IsEnableDiffLogEvent;
|
||||||
|
result.DiffModel = this.diffModel;
|
||||||
|
if (this.UpdateBuilder.DbColumnInfoList.Any())
|
||||||
|
result.UpdateColumns = this.UpdateBuilder.DbColumnInfoList.GroupBy(it => it.TableId).First().Select(it => it.DbColumnName).ToList();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
public IUpdateable<T, T2> InnerJoin<T2>(Expression<Func<T, T2, bool>> joinExpress)
|
public IUpdateable<T, T2> InnerJoin<T2>(Expression<Func<T, T2, bool>> joinExpress)
|
||||||
{
|
{
|
||||||
UpdateableProvider<T, T2> result = new UpdateableProvider<T, T2>();
|
UpdateableProvider<T, T2> result = new UpdateableProvider<T, T2>();
|
||||||
|
@ -3,6 +3,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using System.Security.Permissions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -114,6 +115,7 @@ namespace SqlSugar
|
|||||||
IUpdateable<T> EnableQueryFilter();
|
IUpdateable<T> EnableQueryFilter();
|
||||||
IUpdateable<T> Clone();
|
IUpdateable<T> Clone();
|
||||||
IUpdateable<T,T2> InnerJoin<T2>(Expression<Func<T,T2,bool>> joinExpress);
|
IUpdateable<T,T2> InnerJoin<T2>(Expression<Func<T,T2,bool>> joinExpress);
|
||||||
|
UpdateablePage<T> PageSize(int pageSize);
|
||||||
}
|
}
|
||||||
public interface IUpdateable<T, T2>
|
public interface IUpdateable<T, T2>
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user