Browse Source

Update core

pull/9/MERGE
sunkaixuna 3 years ago
parent
commit
1e82197201
  1. 6
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs
  2. 32
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  3. 9
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs
  4. 10
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  5. 6
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/ContextMethods.cs
  6. 3
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlSugarClient.cs
  7. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs
  8. 8
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/Insertable/OracleInsertable.cs
  9. 9
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs
  10. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs
  11. 4
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs
  12. 12
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConvert.cs

6
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs

@ -733,7 +733,7 @@ namespace SqlSugar
// return asyncInsertable;
//}
private void After(string sql, long? result)
protected void After(string sql, long? result)
{
if (this.IsEnableDiffLogEvent)
{
@ -753,7 +753,7 @@ namespace SqlSugar
this.RemoveCacheFunc();
}
}
private void Before(string sql)
protected void Before(string sql)
{
if (this.IsEnableDiffLogEvent)
{
@ -841,12 +841,14 @@ namespace SqlSugar
{
if (this.InsertObjs.HasValue())
{
var oldColumns = this.InsertBuilder.DbColumnInfoList.Select(it => it.PropertyName).ToList();
var expression = (LambdaExpression.Lambda(method).Body as LambdaExpression).Body;
Check.Exception(!(expression is MethodCallExpression), method.ToString() + " is not method");
var callExpresion = expression as MethodCallExpression;
UtilMethods.DataInoveByExpresson(this.InsertObjs,callExpresion);
this.InsertBuilder.DbColumnInfoList = new List<DbColumnInfo>();
Init();
this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => oldColumns.Contains(it.PropertyName)).ToList();
}
return this;
}

32
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -825,7 +825,7 @@ namespace SqlSugar
}
public virtual bool Any()
{
return this.Count() > 0;
return this.Select("1").First()!=null;
}
public virtual ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression)
@ -893,7 +893,30 @@ namespace SqlSugar
{
var splitColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyInfo.GetCustomAttribute<SplitFieldAttribute>() != null);
var columnName = this.SqlBuilder.GetTranslationColumnName(splitColumn.DbColumnName);
return this.Where($" {columnName}>=@spBeginTime AND {columnName}<= @spEndTime",new { spBeginTime = beginTime , spEndTime = endTime}).SplitTable(tas => tas.Where(y => y.Date >= beginTime && y.Date <= endTime));
return this.Where($" {columnName}>=@spBeginTime AND {columnName}<= @spEndTime",new { spBeginTime = beginTime , spEndTime = endTime}).SplitTable(tas => {
var dateNull = DateTime.MinValue;
var min = tas.Where(it => it.Date <= beginTime.Date).Select(it=>it.Date).OrderByDescending(it=>it.Date).FirstOrDefault();
var max = tas.Where(it => it.Date >= endTime.Date).Select(it => it.Date).OrderBy(it => it.Date).FirstOrDefault();
if (max == dateNull && min == dateNull)
{
return tas.Take(1);
}
if (max == dateNull)
{
max = tas.Where(it => it.Date <= endTime).Select(it => it.Date).OrderByDescending(it => it.Date).FirstOrDefault();
}
if (max == dateNull)
{
max = min;
}
if (min == dateNull)
{
min = max;
}
var result= tas.Where(y => y.Date >= min && y.Date <= max);
return result;
});
}
public ISugarQueryable<T> SplitTable(Func<List<SplitTableInfo>, IEnumerable<SplitTableInfo>> getTableNamesFunc)
{
@ -1181,6 +1204,11 @@ namespace SqlSugar
this.QueryBuilder.ResultType = typeof(SugarCacheDictionary);
var keyName = QueryBuilder.GetExpressionValue(key, ResolveExpressType.FieldSingle).GetResultString();
var valueName = QueryBuilder.GetExpressionValue(value, ResolveExpressType.FieldSingle).GetResultString();
if (this.QueryBuilder.IsSingle() == false)
{
keyName = this.QueryBuilder.TableShortName+ "." + keyName;
valueName = this.QueryBuilder.TableShortName + "." + valueName;
}
var result = this.Select<KeyValuePair<string, object>>(keyName + "," + valueName).ToList().ToDictionary(it => it.Key.ObjToString(), it => it.Value);
return result;
}

9
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs

@ -1168,5 +1168,14 @@ namespace SqlSugar
};
}
#endregion
#region AsTenant
public ITenant AsTenant()
{
Check.Exception(true,ErrorMessage.GetThrowMessage("Child objects do not support tenant methods, var childDb= Db.GetConnection(confid) ,Db is master ", "Db子对象不支持租户方法,请使用主对象,例如:var childDb= Db.GetConnection(confid) Db是主对象,childDb是子对象 "));
return null;
}
#endregion
}
}

10
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -203,12 +203,14 @@ namespace SqlSugar
ThrowUpdateByExpression();
if (this.UpdateObjs.HasValue())
{
var oldColumns = this.UpdateBuilder.DbColumnInfoList.Select(it => it.PropertyName).ToList();
var expression = (LambdaExpression.Lambda(method).Body as LambdaExpression).Body;
Check.Exception(!(expression is MethodCallExpression), method.ToString() + " is not method");
var callExpresion = expression as MethodCallExpression;
UtilMethods.DataInoveByExpresson(this.UpdateObjs, callExpresion);
this.UpdateBuilder.DbColumnInfoList = new List<DbColumnInfo>();
Init();
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => oldColumns.Contains(it.PropertyName)).ToList();
}
return this;
}
@ -316,7 +318,7 @@ namespace SqlSugar
public IUpdateable<T> SetColumns(Expression<Func<T, bool>> columns)
{
ThrowUpdateByObject();
CheckTranscodeing();
var binaryExp = columns.Body as BinaryExpression;
Check.Exception(!binaryExp.NodeType.IsIn(ExpressionType.Equal), "No support {0}", columns.ToString());
Check.Exception(!(binaryExp.Left is MemberExpression) && !(binaryExp.Left is UnaryExpression), "No support {0}", columns.ToString());
@ -327,6 +329,12 @@ namespace SqlSugar
expResult = Regex.Split(expResult, " IS NULL ")[0]+" = NULL ";
}
string key = SqlBuilder.GetNoTranslationColumnName(expResult);
if (EntityInfo.Columns.Where(it=>it.IsJson||it.IsTranscoding).Any(it => it.DbColumnName.EqualCase(key) || it.PropertyName.EqualCase(key)))
{
CheckTranscodeing();
}
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(SqlBuilder.GetTranslationColumnName(key), expResult));
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => (UpdateParameterIsNull == false && IsPrimaryKey(it)) || UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList();
AppendSets();

6
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/ContextMethods.cs

@ -283,7 +283,11 @@ namespace SqlSugar
var typeName = tType.Name;
if (item.PropertyType.IsClass())
{
if (IsJsonItem(readerValues, name))
if (item.PropertyType.FullName == "Newtonsoft.Json.Linq.JObject")
{
result.Add(name, DeserializeObject<dynamic>(readerValues[item.Name].ToString()));
}
else if (IsJsonItem(readerValues, name))
{
result.Add(name, DeserializeObject<Dictionary<string, object>>(readerValues.First().Value.ObjToString()));
}

3
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlSugarClient.cs

@ -52,7 +52,8 @@ namespace SqlSugar
void InitMappingInfo(Type type);
void InitMappingInfo<T>();
void Open();
void Close();
void Close();
ITenant AsTenant();
#endregion
#region Insertable

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs

@ -20,6 +20,8 @@ namespace SqlSugar
csharpTypeName = "long";
if (csharpTypeName == "Boolean")
csharpTypeName = "bool";
if (csharpTypeName == "SByte")
csharpTypeName = "Byte";
var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase));
return mappings.HasValue() ? mappings.First().Key : "varchar";
}

8
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/Insertable/OracleInsertable.cs

@ -34,7 +34,7 @@ namespace SqlSugar
var count = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : GetSeqValue(GetSeqName()).ObjToInt();
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql,result);
AutoEnd(oldIsAuto);
return result;
}
@ -52,7 +52,7 @@ namespace SqlSugar
var count = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : Convert.ToInt64(GetSeqValue(GetSeqName()));
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql, result);
AutoEnd(oldIsAuto);
return result;
}
@ -70,7 +70,7 @@ namespace SqlSugar
var count = await Ado.ExecuteCommandAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : GetSeqValue(GetSeqName()).ObjToInt();
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql, result);
AutoEnd(oldIsAuto);
return result;
}
@ -88,7 +88,7 @@ namespace SqlSugar
var count = await Ado.ExecuteCommandAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : Convert.ToInt64(GetSeqValue(GetSeqName()));
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
After(sql, result);
AutoEnd(oldIsAuto);
return result;
}

9
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs

@ -41,6 +41,15 @@ namespace SqlSugar
{
return base.GetDbColumnName(entityName,propertyName).ToUpper();
}
public override bool IsTranslationText(string name)
{
if (!string.IsNullOrEmpty(name) && name.ToLower() == "sysdate")
{
return true;
}
var result = name.IsContainsIn(SqlTranslationLeft, SqlTranslationRight, UtilConstants.Space, ExpressionConst.LeftParenthesis, ExpressionConst.RightParenthesis);
return result;
}
}
public partial class OracleMethod : DefaultDbMethod, IDbMethods
{

5
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs

@ -576,6 +576,11 @@ namespace SqlSugar
#endregion
#region TenantManager
public ITenant AsTenant()
{
var tenant= this as ITenant;
return tenant;
}
public SqlSguarTransaction UseTran()
{
return new SqlSguarTransaction(this);

4
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs

@ -65,6 +65,10 @@ namespace SqlSugar
public SugarCacheProvider DataCache => ScopedContext.DataCache;
public ITenant AsTenant()
{
return ScopedContext.AsTenant();
}
public void AddConnection(ConnectionConfig connection)
{
ScopedContext.AddConnection(connection);

12
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConvert.cs

@ -55,7 +55,17 @@ namespace SqlSugar
}
return errorValue;
}
public static bool EqualCase(this string thisValue,string equalValue)
{
if ( thisValue!=null && equalValue != null)
{
return thisValue.ToLower() == equalValue.ToLower();
}
else
{
return thisValue == equalValue;
}
}
public static string ObjToString(this object thisValue)
{
if (thisValue != null) return thisValue.ToString().Trim();

Loading…
Cancel
Save