mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-03 20:27:56 +08:00
Update core
This commit is contained in:
parent
3c4f620579
commit
5b19e44d7f
@ -339,6 +339,8 @@ namespace SqlSugar
|
||||
InitParameters(ref sql, parameters);
|
||||
if (FormatSql != null)
|
||||
sql = FormatSql(sql);
|
||||
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle==true)
|
||||
return this.Context.CurrentConnectionConfig.SqlMiddle.ExecuteCommand(sql, parameters);
|
||||
SetConnectionStart(sql);
|
||||
if (this.ProcessingEventStartingSQL != null)
|
||||
ExecuteProcessingSQL(ref sql,ref parameters);
|
||||
@ -371,6 +373,8 @@ namespace SqlSugar
|
||||
InitParameters(ref sql, parameters);
|
||||
if (FormatSql != null)
|
||||
sql = FormatSql(sql);
|
||||
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
|
||||
return this.Context.CurrentConnectionConfig.SqlMiddle.GetDataReader(sql, parameters);
|
||||
SetConnectionStart(sql);
|
||||
var isSp = this.CommandType == CommandType.StoredProcedure;
|
||||
if (this.ProcessingEventStartingSQL != null)
|
||||
@ -403,6 +407,8 @@ namespace SqlSugar
|
||||
InitParameters(ref sql, parameters);
|
||||
if (FormatSql != null)
|
||||
sql = FormatSql(sql);
|
||||
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
|
||||
return this.Context.CurrentConnectionConfig.SqlMiddle.GetDataSetAll(sql, parameters);
|
||||
SetConnectionStart(sql);
|
||||
if (this.ProcessingEventStartingSQL != null)
|
||||
ExecuteProcessingSQL(ref sql,ref parameters);
|
||||
@ -438,6 +444,8 @@ namespace SqlSugar
|
||||
InitParameters(ref sql, parameters);
|
||||
if (FormatSql != null)
|
||||
sql = FormatSql(sql);
|
||||
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
|
||||
return this.Context.CurrentConnectionConfig.SqlMiddle.GetScalar(sql, parameters);
|
||||
SetConnectionStart(sql);
|
||||
if (this.ProcessingEventStartingSQL != null)
|
||||
ExecuteProcessingSQL(ref sql,ref parameters);
|
||||
@ -473,6 +481,8 @@ namespace SqlSugar
|
||||
InitParameters(ref sql, parameters);
|
||||
if (FormatSql != null)
|
||||
sql = FormatSql(sql);
|
||||
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
|
||||
return await this.Context.CurrentConnectionConfig.SqlMiddle.ExecuteCommandAsync(sql, parameters);
|
||||
SetConnectionStart(sql);
|
||||
if (this.ProcessingEventStartingSQL != null)
|
||||
ExecuteProcessingSQL(ref sql,ref parameters);
|
||||
@ -510,6 +520,8 @@ namespace SqlSugar
|
||||
InitParameters(ref sql, parameters);
|
||||
if (FormatSql != null)
|
||||
sql = FormatSql(sql);
|
||||
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
|
||||
return await this.Context.CurrentConnectionConfig.SqlMiddle.GetDataReaderAsync(sql, parameters);
|
||||
SetConnectionStart(sql);
|
||||
var isSp = this.CommandType == CommandType.StoredProcedure;
|
||||
if (this.ProcessingEventStartingSQL != null)
|
||||
@ -547,6 +559,8 @@ namespace SqlSugar
|
||||
InitParameters(ref sql, parameters);
|
||||
if (FormatSql != null)
|
||||
sql = FormatSql(sql);
|
||||
if (this.Context.CurrentConnectionConfig?.SqlMiddle?.IsSqlMiddle == true)
|
||||
return await this.Context.CurrentConnectionConfig.SqlMiddle.GetScalarAsync(sql, parameters);
|
||||
SetConnectionStart(sql);
|
||||
if (this.ProcessingEventStartingSQL != null)
|
||||
ExecuteProcessingSQL(ref sql,ref parameters);
|
||||
|
@ -1276,6 +1276,64 @@ namespace SqlSugar
|
||||
InitMapping();
|
||||
return _ToList<T>();
|
||||
}
|
||||
public virtual void ForEach(Action<T> action, int singleMaxReads = 300,System.Threading.CancellationTokenSource cancellationTokenSource = null)
|
||||
{
|
||||
Check.Exception(this.QueryBuilder.Skip > 0 || this.QueryBuilder.Take > 0, ErrorMessage.GetThrowMessage("no support Skip take, use PageForEach", "不支持Skip Take,请使用 Queryale.PageForEach"));
|
||||
var totalNumber = 0;
|
||||
var totalPage = 1;
|
||||
for (int i = 1; i <= totalPage; i++)
|
||||
{
|
||||
if (cancellationTokenSource?.IsCancellationRequested == true) return;
|
||||
var queryable = this.Clone();
|
||||
var page =
|
||||
totalPage==1?
|
||||
queryable.ToPageList(i, singleMaxReads, ref totalNumber, ref totalPage):
|
||||
queryable.ToPageList(i, singleMaxReads);
|
||||
foreach (var item in page)
|
||||
{
|
||||
if (cancellationTokenSource?.IsCancellationRequested == true) return;
|
||||
action.Invoke(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual void ForEachByPage(Action<T> action, int pageIndex, int pageSize, ref int totalNumber, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null)
|
||||
{
|
||||
int count = this.Clone().Count();
|
||||
if (count > 0)
|
||||
{
|
||||
if (pageSize > singleMaxReads && count - ((pageIndex - 1) * pageSize) > singleMaxReads)
|
||||
{
|
||||
Int32 Skip = (pageIndex - 1) * pageSize;
|
||||
Int32 NowCount = count - Skip;
|
||||
Int32 number = 0;
|
||||
if (NowCount > pageSize) NowCount = pageSize;
|
||||
while (NowCount > 0)
|
||||
{
|
||||
if (cancellationTokenSource?.IsCancellationRequested == true) return;
|
||||
if (number + singleMaxReads > pageSize) singleMaxReads = NowCount;
|
||||
foreach (var item in this.Clone().Skip(Skip).Take(singleMaxReads).ToList())
|
||||
{
|
||||
if (cancellationTokenSource?.IsCancellationRequested == true) return;
|
||||
action.Invoke(item);
|
||||
}
|
||||
NowCount -= singleMaxReads;
|
||||
Skip += singleMaxReads;
|
||||
number += singleMaxReads;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cancellationTokenSource?.IsCancellationRequested == true) return;
|
||||
foreach (var item in this.Clone().ToPageList(pageIndex, pageSize))
|
||||
{
|
||||
if (cancellationTokenSource?.IsCancellationRequested == true) return;
|
||||
action.Invoke(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
totalNumber = count;
|
||||
}
|
||||
|
||||
public List<T> ToOffsetPage(int pageIndex, int pageSize)
|
||||
{
|
||||
if (this.Context.CurrentConnectionConfig.DbType != DbType.SqlServer)
|
||||
|
@ -86,6 +86,7 @@ namespace SqlSugar
|
||||
IsWithNoLockQuery = it.MoreSettings.IsWithNoLockQuery,
|
||||
TableEnumIsString=it.MoreSettings.TableEnumIsString
|
||||
},
|
||||
SqlMiddle=it.SqlMiddle,
|
||||
SlaveConnectionConfigs = it.SlaveConnectionConfigs
|
||||
}).ToList();
|
||||
}
|
||||
|
@ -169,6 +169,11 @@ namespace SqlSugar
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => !ignoreColumns.Contains(it.DbColumnName.ToLower())).ToList();
|
||||
return this;
|
||||
}
|
||||
public IUpdateable<T> IgnoreColumnsIF(bool IsIgnore, Expression<Func<T, object>> columns)
|
||||
{
|
||||
if (IsIgnore) this.IgnoreColumns(columns);
|
||||
return this;
|
||||
}
|
||||
public IUpdateable<T> IgnoreColumns(string[] columns)
|
||||
{
|
||||
if (columns.HasValue())
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
@ -61,6 +62,23 @@ namespace SqlSugar
|
||||
|
||||
[JsonIgnore]
|
||||
public AopEvents AopEvents { get;set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public SqlMiddle SqlMiddle { get; set; }
|
||||
}
|
||||
public class SqlMiddle
|
||||
{
|
||||
public bool? IsSqlMiddle { get; set; }
|
||||
public Func<string, SugarParameter[], object> GetScalar { get; set; } = (s,p) => throw new NotSupportedException("SqlMiddle.GetScalar");
|
||||
public Func<string, SugarParameter[],int> ExecuteCommand { get; set; } = (s, p) => throw new NotSupportedException("SqlMiddle.ExecuteCommand");
|
||||
public Func<string, SugarParameter[],IDataReader> GetDataReader { get; set; } = (s, p) => throw new NotSupportedException("SqlMiddle.GetDataReader");
|
||||
public Func<string, SugarParameter[],DataSet> GetDataSetAll { get; set; } = (s, p) => throw new NotSupportedException("SqlMiddle.GetDataSetAll");
|
||||
public Func<string, SugarParameter[], Task<object>> GetScalarAsync { get; set; } = (s, p) => throw new NotSupportedException("SqlMiddle.GetScalarAsync");
|
||||
public Func<string, SugarParameter[], Task<int>> ExecuteCommandAsync { get; set; } = (s, p) => throw new NotSupportedException("SqlMiddle.ExecuteCommandAsync");
|
||||
public Func<string, SugarParameter[], Task<IDataReader>> GetDataReaderAsync { get; set; } = (s, p) => throw new NotSupportedException("SqlMiddle.GetDataReaderAsync");
|
||||
public Func<string, SugarParameter[], Task<DataSet>> GetDataSetAllAsync { get; set; } = (s, p) => throw new NotSupportedException("SqlMiddle.GetDataSetAllAsync");
|
||||
|
||||
}
|
||||
public class AopEvents
|
||||
{
|
||||
|
@ -108,7 +108,8 @@ namespace SqlSugar
|
||||
ISugarQueryable<TResult> Select<TResult>(string select);
|
||||
ISugarQueryable<T> Select(string select);
|
||||
ISugarQueryable<T> MergeTable();
|
||||
|
||||
void ForEach(Action<T> action, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
||||
void ForEachByPage(Action<T> action, int pageIndex, int pageSize, ref int totalNumber, int singleMaxReads = 300, System.Threading.CancellationTokenSource cancellationTokenSource = null);
|
||||
int Count();
|
||||
Task<int> CountAsync();
|
||||
int Count(Expression<Func<T, bool>> expression);
|
||||
|
@ -80,6 +80,8 @@ namespace SqlSugar
|
||||
|
||||
IUpdateable<T> IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false, bool ignoreAllDefaultValue = false);
|
||||
IUpdateable<T> IgnoreColumns(Expression<Func<T, object>> columns);
|
||||
IUpdateable<T> IgnoreColumnsIF(bool isIgnore, Expression<Func<T, object>> columns);
|
||||
|
||||
IUpdateable<T> IgnoreColumns(params string[] columns);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user