Browse Source

Update core

pull/14/MERGE
sunkaixuan 3 years ago
parent
commit
5b19e44d7f
  1. 14
      Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
  2. 58
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  3. 1
      Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarCoreProvider.cs
  4. 5
      Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  5. 18
      Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs
  6. 3
      Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs
  7. 2
      Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs

14
Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs

@ -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);

58
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -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)

1
Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarCoreProvider.cs

@ -86,6 +86,7 @@ namespace SqlSugar
IsWithNoLockQuery = it.MoreSettings.IsWithNoLockQuery,
TableEnumIsString=it.MoreSettings.TableEnumIsString
},
SqlMiddle=it.SqlMiddle,
SlaveConnectionConfigs = it.SlaveConnectionConfigs
}).ToList();
}

5
Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -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())

18
Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs

@ -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
{

3
Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

@ -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);

2
Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs

@ -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…
Cancel
Save