Browse Source

Update .net core

SqlSugar5
sunkaixuan 2 years ago
parent
commit
020aeabaaa
  1. 12
      Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
  2. 1
      Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs
  3. 21
      Src/Asp.NetCore2/SqlSugar/Abstract/DbBindProvider/DbBindAccessory.cs
  4. 2
      Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs
  5. 19
      Src/Asp.NetCore2/SqlSugar/Enum/DataFilterType.cs
  6. 1
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs
  7. 1
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs
  8. 19
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs
  9. 1
      Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs
  10. 1
      Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs

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

@ -87,6 +87,18 @@ namespace SqlSugar
return false;
}
}
public virtual bool IsValidConnectionNoClose()
{
try
{
this.Open();
return true;
}
catch (Exception)
{
return false;
}
}
public virtual void Open()
{
CheckConnection();

1
Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs

@ -20,5 +20,6 @@ namespace SqlSugar
public Action<string, SugarParameter[]> OnLogExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.OnLogExecuted = value; } }
public Func<string, SugarParameter[], KeyValuePair<string, SugarParameter[]>> OnExecutingChangeSql { set { this.Context.CurrentConnectionConfig.AopEvents.OnExecutingChangeSql = value; } }
public virtual Action<object, DataFilterModel> DataExecuting { set { this.Context.CurrentConnectionConfig.AopEvents.DataExecuting = value; } }
public virtual Action<object, DataAfterModel> DataExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.DataExecuted = value; } }
}
}

21
Src/Asp.NetCore2/SqlSugar/Abstract/DbBindProvider/DbBindAccessory.cs

@ -16,6 +16,7 @@ namespace SqlSugar
string types = null;
var fieldNames = GetDataReaderNames(dataReader,ref types);
string cacheKey = GetCacheKey(type,fieldNames) + types;
var dataAfterFunc = context.CurrentConnectionConfig?.AopEvents?.DataExecuted;
IDataReaderEntityBuilder<T> entytyList = context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey, () =>
{
var cacheResult = new IDataReaderEntityBuilder<T>(context, dataReader,fieldNames).CreateBuilder(type);
@ -29,6 +30,7 @@ namespace SqlSugar
{
result.Add(entytyList.Build(dataReader));
}
ExecuteDataAfterFun(context, dataAfterFunc, result);
}
catch (Exception ex)
{
@ -36,12 +38,14 @@ namespace SqlSugar
}
return result;
}
protected async Task<List<T>> GetEntityListAsync<T>(SqlSugarProvider context, IDataReader dataReader)
{
Type type = typeof(T);
string types = null;
var fieldNames = GetDataReaderNames(dataReader,ref types);
string cacheKey = GetCacheKey(type, fieldNames)+types;
var dataAfterFunc = context.CurrentConnectionConfig?.AopEvents?.DataExecuted;
IDataReaderEntityBuilder<T> entytyList = context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey, () =>
{
var cacheResult = new IDataReaderEntityBuilder<T>(context, dataReader, fieldNames).CreateBuilder(type);
@ -55,6 +59,7 @@ namespace SqlSugar
{
result.Add(entytyList.Build(dataReader));
}
ExecuteDataAfterFun(context, dataAfterFunc, result);
}
catch (Exception ex)
{
@ -62,6 +67,22 @@ namespace SqlSugar
}
return result;
}
private static void ExecuteDataAfterFun<T>(SqlSugarProvider context, Action<object, DataAfterModel> dataAfterFunc, List<T> result)
{
if (dataAfterFunc != null)
{
var entity = context.EntityMaintenance.GetEntityInfo<T>();
foreach (var item in result)
{
dataAfterFunc(item, new DataAfterModel()
{
EntityColumnInfos = entity.Columns,
Entity = entity,
EntityValue = item
});
}
}
}
private string GetCacheKey(Type type,List<string> keys)
{

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

@ -88,7 +88,7 @@ namespace SqlSugar
public Action<string, SugarParameter[]> OnLogExecuted { get; set; }
public Func<string, SugarParameter[], KeyValuePair<string, SugarParameter[]>> OnExecutingChangeSql { get; set; }
public Action<object, DataFilterModel> DataExecuting { get; set; }
public Action<object, DataAfterModel> DataExecuted { get; set; }
}
public class ConfigureExternalServices
{

19
Src/Asp.NetCore2/SqlSugar/Enum/DataFilterType.cs

@ -31,4 +31,23 @@ namespace SqlSugar
this.EntityColumnInfo.PropertyInfo.SetValue(EntityValue, value);
}
}
public class DataAfterModel
{
public List<EntityColumnInfo> EntityColumnInfos { get; set; }
public object EntityValue { get; set; }
public EntityInfo Entity { get; set; }
public object GetValue(string propertyName)
{
var propety=EntityColumnInfos.FirstOrDefault(it => it.PropertyName == propertyName);
Check.ExceptionEasy(propety==null,$"Aop.DataExecuted error . { Entity.EntityName} no property {propertyName}.", $"Aop.DataExecuted 出错 {Entity.EntityName}不存在属性{propertyName}");
return propety.PropertyInfo.GetValue(EntityValue);
}
public void SetValue(string propertyName,object value)
{
var propety = EntityColumnInfos.FirstOrDefault(it => it.PropertyName == propertyName);
Check.ExceptionEasy(propety == null, $"Aop.DataExecuted error . { Entity.EntityName} no property {propertyName}.", $"Aop.DataExecuted 出错 {Entity.EntityName}不存在属性{propertyName}");
propety.PropertyInfo.SetValue(EntityValue,value);
}
}
}

1
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs

@ -46,6 +46,7 @@ namespace SqlSugar
var name =this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters[0].Name);
var parameter = (argExp as LambdaExpression).Parameters.Last();
Context.InitMappingInfo(parameter.Type);
this.Context.RefreshMapping();
var tableName= Context.GetTranslationTableName(parameter.Type.Name, true);
var joinString =string.Format(" {2} INNER JOIN {1} {0} ",
this.Context.GetTranslationColumnName(parameter.Name),

1
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs

@ -46,6 +46,7 @@ namespace SqlSugar
var name =this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters[0].Name);
var parameter = (argExp as LambdaExpression).Parameters.Last();
Context.InitMappingInfo(parameter.Type);
this.Context.RefreshMapping();
var tableName= Context.GetTranslationTableName(parameter.Type.Name, true);
var joinString =string.Format(" {2} LEFT JOIN {1} {0} ",
this.Context.GetTranslationColumnName(parameter.Name),

19
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs

@ -43,12 +43,7 @@ namespace SqlSugar
public string GetValue(Expression expression = null)
{
var exp = expression as MethodCallExpression;
var entityType = (exp.Arguments[0] as LambdaExpression).Parameters[0].Type;
if (this.Context.InitMappingInfo != null)
{
this.Context.InitMappingInfo(entityType);
this.Context.RefreshMapping();
}
InitType(exp);
var result = "";
if (this.Context.JoinIndex == 0)
result = SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle);
@ -60,6 +55,18 @@ namespace SqlSugar
return result;
}
private void InitType(MethodCallExpression exp)
{
foreach (var arg in (exp.Arguments[0] as LambdaExpression).Parameters)
{
if (this.Context.InitMappingInfo != null)
{
this.Context.InitMappingInfo(arg.Type);
this.Context.RefreshMapping();
}
}
}
public void SetShortName(MethodCallExpression exp, string result)
{
if (exp.Arguments[0] is LambdaExpression && result.IsContainsIn("+", "-","*","/"))

1
Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs

@ -165,6 +165,7 @@ namespace SqlSugar
void Open();
SugarConnection OpenAlways();
bool IsValidConnection();
bool IsValidConnectionNoClose();
void CheckConnection();
void BeginTran();

1
Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs

@ -87,6 +87,7 @@ namespace SqlSugar
OnExecutingChangeSql=it.AopEvents?.OnExecutingChangeSql,
OnLogExecuted=it.AopEvents?.OnLogExecuted,
OnLogExecuting= it.AopEvents?.OnLogExecuting,
DataExecuted = it.AopEvents?.DataExecuted,
},
ConfigId = it.ConfigId,
ConfigureExternalServices =it.ConfigureExternalServices==null?null:new ConfigureExternalServices() {

Loading…
Cancel
Save