diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index b7c2dbccd..fe9b2a91c 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/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(); Init(); + this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => oldColumns.Contains(it.PropertyName)).ToList(); } return this; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 10148c6b5..f30eda42f 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/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 Select(Expression> expression) @@ -893,7 +893,30 @@ namespace SqlSugar { var splitColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.PropertyInfo.GetCustomAttribute() != 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 SplitTable(Func, IEnumerable> 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>(keyName + "," + valueName).ToList().ToDictionary(it => it.Key.ObjToString(), it => it.Value); return result; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs index 54c7c2bf6..eae1f92b6 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs +++ b/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 + } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index 0c233aba6..dcbd922c3 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/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(); Init(); + this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => oldColumns.Contains(it.PropertyName)).ToList(); } return this; } @@ -316,7 +318,7 @@ namespace SqlSugar public IUpdateable SetColumns(Expression> 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(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(); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/ContextMethods.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/ContextMethods.cs index b7e70a5d3..98be67fdd 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/ContextMethods.cs +++ b/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(readerValues[item.Name].ToString())); + } + else if (IsJsonItem(readerValues, name)) { result.Add(name, DeserializeObject>(readerValues.First().Value.ObjToString())); } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlSugarClient.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlSugarClient.cs index 2d98e2e94..df631a1e2 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlSugarClient.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlSugarClient.cs @@ -52,7 +52,8 @@ namespace SqlSugar void InitMappingInfo(Type type); void InitMappingInfo(); void Open(); - void Close(); + void Close(); + ITenant AsTenant(); #endregion #region Insertable diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs index c85e4268a..04ea3e886 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs +++ b/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"; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/Insertable/OracleInsertable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/Insertable/OracleInsertable.cs index 029220353..881c71f55 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/Insertable/OracleInsertable.cs +++ b/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; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs index 63025c0b5..18049ff6b 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs +++ b/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 { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs index 83bbe2496..58863ef59 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs +++ b/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); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs index 7db6e93dd..32a45b810 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs +++ b/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); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConvert.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConvert.cs index e141dcb15..1e535a2ea 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConvert.cs +++ b/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();