diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs index 233e19033..ac861cbb0 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs @@ -306,13 +306,13 @@ namespace SqlSugar } public virtual bool CreateIndex(string tableName, string[] columnNames, bool isUnique=false) { - string sql = string.Format(CreateIndexSql,tableName,string.Join(",",columnNames), string.Join("_", columnNames), isUnique ? "UNIQUE" : ""); + string sql = string.Format(CreateIndexSql,tableName,string.Join(",",columnNames), string.Join("_", columnNames) + this.Context.CurrentConnectionConfig.IndexSuffix, isUnique ? "UNIQUE" : ""); this.Context.Ado.ExecuteCommand(sql); return true; } public virtual bool CreateUniqueIndex(string tableName, string[] columnNames) { - string sql = string.Format(CreateIndexSql, tableName, string.Join(",", columnNames), string.Join("_", columnNames)+"_Unique","UNIQUE" ); + string sql = string.Format(CreateIndexSql, tableName, string.Join(",", columnNames), string.Join("_", columnNames) + this.Context.CurrentConnectionConfig.IndexSuffix + "_Unique","UNIQUE" ); this.Context.Ado.ExecuteCommand(sql); return true; } @@ -370,7 +370,7 @@ namespace SqlSugar foreach (var item in groups) { var columnNames = indexColumns.Where(it => it.IndexGroupNameList.Any(i => i.Equals(item, StringComparison.CurrentCultureIgnoreCase))).Select(it=>it.DbColumnName).ToArray(); - var indexName = string.Format("Index_{0}_{1}",entityInfo.DbTableName, string.Join("_", columnNames)); + var indexName = string.Format("Index_{0}_{1}"+this.Context.CurrentConnectionConfig.IndexSuffix,entityInfo.DbTableName, string.Join("_", columnNames)); if (!IsAnyIndex(indexName)) { CreateIndex(entityInfo.DbTableName, columnNames); @@ -386,7 +386,7 @@ namespace SqlSugar foreach (var item in groups) { var columnNames = uIndexColumns.Where(it => it.UIndexGroupNameList.Any(i => i.Equals(item, StringComparison.CurrentCultureIgnoreCase))).Select(it => it.DbColumnName).ToArray(); - var indexName = string.Format("Index_{0}_{1}_Unique", entityInfo.DbTableName, string.Join("_", columnNames)); + var indexName = string.Format("Index_{0}_{1}_Unique" + this.Context.CurrentConnectionConfig.IndexSuffix, entityInfo.DbTableName, string.Join("_", columnNames)); if (!IsAnyIndex(indexName)) { CreateUniqueIndex(entityInfo.DbTableName, columnNames); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index 47c167c3e..92b5e682a 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -669,24 +669,5 @@ namespace SqlSugar } #endregion - #region Obsolete - [Obsolete] - public IInsertable InsertColumns(Func insertColumMethod) - { - this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => insertColumMethod(it.PropertyName)).ToList(); - return this; - } - [Obsolete] - public IInsertable IgnoreColumns(Func ignoreColumMethod) - { - this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => !ignoreColumMethod(it.PropertyName)).ToList(); - return this; - } - [Obsolete] - public IInsertable Where(bool ignoreNullColumn, bool isOffIdentity = false) - { - return IgnoreColumns(ignoreNullColumn, isOffIdentity); - } - #endregion } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 37f090aa1..61bf2d832 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -129,6 +129,12 @@ namespace SqlSugar } public virtual ISugarQueryable Mapper(Expression>> mapperObject, Expression> mapperField) { + Check.Exception(mapperObject.ReturnType.Name == "IList`1", "Mapper no support IList , Use List"); + if (CallContext.MapperExpression.Value == null) + { + CallContext.MapperExpression.Value = new List(); + } + CallContext.MapperExpression.Value.Add(new MapperExpression() { SqlBuilder = SqlBuilder, QueryBuilder = this.QueryBuilder, Type = MapperExpressionType.oneToN, FillExpression = mapperObject, MappingField1Expression = mapperField,Context = this.Context }); return _Mapper(mapperObject, mapperField); } public virtual ISugarQueryable Mapper(Expression> mapperObject, Expression> mapperField) @@ -609,15 +615,8 @@ namespace SqlSugar Check.Exception(this.MapperAction != null || this.MapperActionWithCache != null, "'Mapper’ needs to be written after ‘MergeTable’ "); Check.Exception(this.QueryBuilder.SelectValue.IsNullOrEmpty(), "MergeTable need to use Queryable.Select Method ."); Check.Exception(this.QueryBuilder.Skip > 0 || this.QueryBuilder.Take > 0 || this.QueryBuilder.OrderByValue.HasValue(), "MergeTable Queryable cannot Take Skip OrderBy PageToList "); - ToSqlBefore(); - var sql = QueryBuilder.ToSqlString(); - var tableName = this.SqlBuilder.GetPackTable(sql, "MergeTable"); - var mergeQueryable = this.Context.Queryable(); - mergeQueryable.QueryBuilder.Parameters = QueryBuilder.Parameters; - mergeQueryable.QueryBuilder.WhereIndex = QueryBuilder.WhereIndex + 1; - mergeQueryable.QueryBuilder.JoinIndex = QueryBuilder.JoinIndex + 1; - mergeQueryable.QueryBuilder.LambdaExpressions.ParameterIndex = QueryBuilder.LambdaExpressions.ParameterIndex; - return mergeQueryable.AS(tableName).Select("*"); + var sqlobj = this.ToSql(); + return this.Context.Queryable().AS(SqlBuilder.GetPackTable(sqlobj.Key, "MergeTable")).AddParameters(sqlobj.Value).Select("*").With(SqlWith.Null); } public ISugarQueryable Distinct() @@ -3387,6 +3386,41 @@ namespace SqlSugar _GroupBy(expression); return this; } + public new ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public new ISugarQueryable Having(string whereString, object whereObj) + { + base.Having(whereString, whereObj); + return this; + } #endregion #region Aggr @@ -3774,6 +3808,46 @@ namespace SqlSugar _GroupBy(expression); return this; } + public new ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public new ISugarQueryable Having(string whereString, object whereObj) + { + base.Having(whereString, whereObj); + return this; + } #endregion #region Aggr diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs index 4a56aa0b2..b5af401cf 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs @@ -323,6 +323,23 @@ namespace SqlSugar #endregion #region Private methods + internal string GetN() + { + var N = "N"; + if (_Context.CurrentConnectionConfig.MoreSettings != null && _Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar) + { + N = ""; + } + return N; + } + internal bool IsVarchar() + { + if (_Context.CurrentConnectionConfig.MoreSettings != null && _Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar) + { + return true; + } + return false; + } private static void CheckDbDependency(ConnectionConfig config) { switch (config.DbType) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index 44d27eeaf..247c292d5 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -315,68 +315,7 @@ namespace SqlSugar return this; } - - - - #region delete obj - [Obsolete] - public IUpdateable UpdateColumns(Expression> columns) - { - return this.SetColumns(columns); - } - [Obsolete] - public IUpdateable UpdateColumns(Expression> columns) - { - return this.SetColumns(columns); - } - [Obsolete] - public IUpdateable UpdateColumnsIF(bool isUpdateColumns, Expression> columns) - { - return this.SetColumnsIF(isUpdateColumns, columns); - } - [Obsolete] - public IUpdateable UpdateColumnsIF(bool isUpdateColumns, Expression> columns) - { - return this.SetColumnsIF(isUpdateColumns, columns); - } - [Obsolete] - public IUpdateable UpdateColumnsIF(bool isUpdateColumns, Func updateColumMethod) - { - if (isUpdateColumns) - UpdateColumns(updateColumMethod); - return this; - } - [Obsolete] - public IUpdateable UpdateColumns(Func updateColumMethod) - { - List primaryKeys = GetPrimaryKeys(); - foreach (var item in this.UpdateBuilder.DbColumnInfoList) - { - var mappingInfo = primaryKeys.SingleOrDefault(i => item.DbColumnName.Equals(i, StringComparison.CurrentCultureIgnoreCase)); - if (mappingInfo != null && mappingInfo.Any()) - { - item.IsPrimarykey = true; - } - } - this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => updateColumMethod(it.PropertyName) || it.IsPrimarykey || it.IsIdentity).ToList(); - return this; - } - [Obsolete] - public IUpdateable IgnoreColumns(Func ignoreColumMethod) - { - this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => !ignoreColumMethod(it.PropertyName)).ToList(); - return this; - } - [Obsolete("Use IUpdateable IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false);")] - public IUpdateable Where(bool isUpdateNull, bool IsOffIdentity = false) - { - UpdateBuilder.IsOffIdentity = IsOffIdentity; - if (this.UpdateBuilder.LambdaExpressions == null) - this.UpdateBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig); - this.UpdateBuilder.IsNoUpdateNull = isUpdateNull; - return this; - } - #endregion + #region Helper private void AppendSets() diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnMoreSettings.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnMoreSettings.cs index 43bad2e40..8ed33faa0 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnMoreSettings.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnMoreSettings.cs @@ -9,10 +9,8 @@ namespace SqlSugar { public bool IsAutoRemoveDataCache { get; set; } public bool IsWithNoLockQuery { get; set; } - /// - /// Some MYSQL databases do not support NVarchar set true - /// - public bool MySqlDisableNarvchar { get; set; } + + public bool DisableNvarchar { get; set; } public bool PgSqlIsAutoToLower = true; public int DefaultCacheDurationInSeconds { get; set; } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnectionConfig.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnectionConfig.cs index e5e06b83f..d95d68298 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnectionConfig.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnectionConfig.cs @@ -52,6 +52,8 @@ namespace SqlSugar /// public SugarDebugger Debugger { get; set; } + public string IndexSuffix { get; set; } + [JsonIgnore] public AopEvents AopEvents { get;set; } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MapperExpressionResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MapperExpressionResolve.cs index 3e6be26da..8a1548d95 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MapperExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MapperExpressionResolve.cs @@ -33,7 +33,19 @@ namespace SqlSugar private void ResolveList() { - throw new NotImplementedException(); + var methodExpression = expression as MethodCallExpression; + var callName = methodExpression.Method.Name; + var exp= methodExpression.Arguments[0] as MemberExpression; + ThrowTrue(exp == null); + var childExpression = exp; + MapperExpression mapper = GetMapperMany(exp); + var fillInfo = GetFillInfoMany(childExpression, mapper); + var mappingFild1Info = GetMappingFild1ManyInfo(childExpression, mapper); + var mappingFild1Info2 = GetMappingFild2Info(childExpression, mapper); + //var SelectInfo = GetSelectInfo(expression); + this.context.InitMappingInfo(childExpression.Expression.Type); + var entity = this.context.EntityMaintenance.GetEntityInfo(childExpression.Expression.Type); + oneToMany(callName, entity, childExpression.Expression.ToString(), fillInfo, mappingFild1Info, mappingFild1Info2); } private void ResolveMember() @@ -62,7 +74,7 @@ namespace SqlSugar } else if (isFillFild1SameType) { - oneToMany(); + throw new NotSupportedException(expression.ToString()); } else { @@ -87,9 +99,31 @@ namespace SqlSugar .Select(sqlBuilder.GetTranslationColumnName(selectInfo.FieldName)).ToSql().Key; } - private void oneToMany() + private void oneToMany(string methodName,EntityInfo mainEntity,string shortName,MapperExpressionInfo fillInfo, MapperExpressionInfo mappingFild1Info, MapperExpressionInfo mappingFild1Info2) { - throw new NotImplementedException(); + var pkColumn = mainEntity.Columns.FirstOrDefault(it=>it.IsPrimarykey==true); + if (pkColumn == null) + { + pkColumn = mainEntity.Columns.FirstOrDefault(); + } + var tableName = sqlBuilder.GetTranslationTableName(fillInfo.EntityInfo.DbTableName); + var whereLeft = sqlBuilder.GetTranslationColumnName(mappingFild1Info.FieldString); + var whereRight = sqlBuilder.GetTranslationColumnName(shortName+"."+pkColumn.DbColumnName); + + if (methodName == "Any") + { + this.sql = " ("+this.context.Queryable() + .AS(tableName) + .Where(string.Format(" {0}={1} ", whereLeft, whereRight)) + .Select("COUNT(1)").ToSql().Key+")>0 "; + } + else + { + this.sql = this.context.Queryable() + .AS(tableName) + .Where(string.Format(" {0}={1} ", whereLeft, whereRight)) + .Select("COUNT(1)").ToSql().Key; + } } private MapperExpressionInfo GetSelectInfo(Expression expression) @@ -205,6 +239,55 @@ namespace SqlSugar return new MapperSql() { Sql = " (" + this.sql + ") " }; } + private MapperExpression GetMapperMany(MemberExpression exp) + { + var mapper = mappers.Where(it => it.Type == MapperExpressionType.oneToN) + .Reverse() + .Where(it => (it.FillExpression as LambdaExpression).Body.ToString() == exp.ToString()).FirstOrDefault(); + ThrowTrue(mapper == null); + return mapper; + } + private MapperExpressionInfo GetFillInfoMany(Expression childExpression, MapperExpression mapper) + { + this.querybuiler = mapper.QueryBuilder; + this.context = mapper.Context; + this.sqlBuilder = mapper.SqlBuilder; + if (this.querybuiler.TableShortName.IsNullOrEmpty()) + { + this.querybuiler.TableShortName = (childExpression as MemberExpression).Expression.ToString(); + } + var type = (childExpression as MemberExpression).Type.GetGenericArguments()[0]; + this.context.InitMappingInfo(type); + return new MapperExpressionInfo() + { + EntityInfo = this.context.EntityMaintenance.GetEntityInfo(type) + }; + } + private MapperExpressionInfo GetMappingFild1ManyInfo(Expression childExpression, MapperExpression mapper) + { + var exp = mapper.MappingField1Expression; + var field = (exp as LambdaExpression).Body; + if (field is UnaryExpression) + { + field = (field as UnaryExpression).Operand; + } + var type = ((field as MemberExpression).Expression).Type; + this.context.InitMappingInfo(type); + var name = (field as MemberExpression).Member.Name; + var entity = this.context.EntityMaintenance.GetEntityInfo(type); + var fieldName = entity.Columns.First(it => it.PropertyName == name).DbColumnName; + //var array = (field as MemberExpression).ToString().Split('.').ToList(); + //array[array.Count() - 1] = fieldName; + //var filedString = string.Join(".", array); + return new MapperExpressionInfo() + { + Type = type, + FieldName = fieldName, + FieldString = fieldName, + EntityInfo = entity + }; + } + void Error01() { Check.Exception(mappers == null, ErrorMessage.GetThrowMessage(expression.ToString() + "no support", "当前表达式" + expression.ToString() + "必须在Mapper之后使用")); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs index e42f26bd8..fae2c88e3 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs @@ -154,6 +154,10 @@ namespace SqlSugar else if (item is BinaryExpression) { var result = GetNewExpressionValue(item); + if (result.HasValue()) + { + result = result.Replace(",", UtilConstants.ReplaceCommaKey); + } this.Context.Result.Append(base.Context.GetEqString(memberName, result)); } else if (item is MemberInitExpression) @@ -182,6 +186,11 @@ namespace SqlSugar throw new NotSupportedException("Not Supported " + item.ToString() + " " + ex.Message); } } + else if (item is ConditionalExpression) + { + var result = GetNewExpressionValue(item); + this.Context.Result.Append(base.Context.GetEqString(memberName, result)); + } } } private static bool IsConst(Expression item) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs index bf683519a..fe47c16fc 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs @@ -154,6 +154,12 @@ namespace SqlSugar try { var constValue = ExpressionTool.DynamicInvoke(express); + if (constValue is MapperSql) + { + constValue = (constValue as MapperSql).Sql; + base.AppendValue(parameter, isLeft, constValue); + return; + } parameter.BaseParameter.CommonTempData = constValue; var parameterName = base.AppendParameter(constValue); if (parameter.BaseParameter.CommonTempData != null && parameter.BaseParameter.CommonTempData.Equals(CommonTempDataType.Result)) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IQueryable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IQueryable.cs index 34685405d..e522f4dcb 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IQueryable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IQueryable.cs @@ -496,6 +496,12 @@ namespace SqlSugar ISugarQueryable GroupBy(Expression> expression); ISugarQueryable GroupBy(Expression> expression); ISugarQueryable GroupBy(Expression> expression); + new ISugarQueryable Having(Expression> expression); + ISugarQueryable Having(Expression> expression); + ISugarQueryable Having(Expression> expression); + ISugarQueryable Having(Expression> expression); + ISugarQueryable Having(Expression> expression); + new ISugarQueryable Having(string whereString, object parameters = null); #endregion #region Aggr @@ -594,6 +600,13 @@ namespace SqlSugar ISugarQueryable GroupBy(Expression> expression); ISugarQueryable GroupBy(Expression> expression); ISugarQueryable GroupBy(Expression> expression); + new ISugarQueryable Having(Expression> expression); + ISugarQueryable Having(Expression> expression); + ISugarQueryable Having(Expression> expression); + ISugarQueryable Having(Expression> expression); + ISugarQueryable Having(Expression> expression); + ISugarQueryable Having(Expression> expression); + new ISugarQueryable Having(string whereString, object parameters = null); #endregion #region Aggr diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISimpleClient.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISimpleClient.cs index 91f81ce28..7d1a8f31c 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISimpleClient.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISimpleClient.cs @@ -35,6 +35,7 @@ namespace SqlSugar bool InsertRange(List insertObjs); bool InsertRange(T[] insertObjs); int InsertReturnIdentity(T insertObj); + long InsertReturnBigIdentity(T insertObj); bool IsAny(Expression> whereExpression); bool Update(Expression> columns, Expression> whereExpression); bool Update(T updateObj); @@ -61,6 +62,7 @@ namespace SqlSugar Task InsertRangeAsync(List insertObjs); Task InsertRangeAsync(T[] insertObjs); Task InsertReturnIdentityAsync(T insertObj); + Task InsertReturnBigIdentityAsync(T insertObj); Task IsAnyAsync(Expression> whereExpression); Task UpdateAsync(Expression> columns, Expression> whereExpression); Task UpdateAsync(T updateObj); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs index 489c96200..82dd5f3d5 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IUpdateable.cs @@ -89,27 +89,6 @@ namespace SqlSugar IUpdateable RemoveDataCache(); KeyValuePair> ToSql(); void AddQueue(); - - - #region delete obj - - [Obsolete("Use IUpdateable UpdateColumns(string [] columns)")] - IUpdateable UpdateColumns(Func updateColumMethod); - [Obsolete("Use IUpdateable IgnoreColumns(string [] columns)")] - IUpdateable IgnoreColumns(Func ignoreColumMethod); - [Obsolete("Use IUpdateable IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false);")] - IUpdateable Where(bool isNoUpdateNull, bool IsOffIdentity = false); - [Obsolete("Use IUpdateable UpdateColumnsIF(bool isUpdateColumns,string [] columns")] - IUpdateable UpdateColumnsIF(bool isUpdateColumns, Func updateColumMethod); - [Obsolete("Use SetColumns(Expression> columns)")] - IUpdateable UpdateColumns(Expression> columns); - [Obsolete("Use SetColumns(Expression> columns")] - IUpdateable UpdateColumns(Expression> columns); - - [Obsolete("Use SetColumnsIF(bool isUpdateColumns, Expression> columns)")] - IUpdateable UpdateColumnsIF(bool isUpdateColumns, Expression> columns); - [Obsolete("Use SetColumnsIF(bool isUpdateColumns, Expression> columns")] - IUpdateable UpdateColumnsIF(bool isUpdateColumns, Expression> columns); - #endregion + } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/Insertable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/Insertable.cs index fb68b0460..497774703 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/Insertable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/Insertable.cs @@ -39,14 +39,5 @@ namespace SqlSugar MySqlBlueCopy UseMySql(); void AddQueue(); - #region Obsolete - [Obsolete("use IgnoreColumns(string[] columns")] - - IInsertable IgnoreColumns(Func ignoreColumMethod); - [Obsolete("use InsertColumns(string[] columns")] - IInsertable InsertColumns(Func insertColumMethod); - [Obsolete("use IgnoreColumns(bool isNoInsertNull, bool isOffIdentity = false)")] - IInsertable Where(bool ignoreNullColumn, bool isOffIdentity = false); - #endregion } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Dm/DmProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Dm/DmProvider.cs index 4c469218f..eb495c950 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Dm/DmProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Dm/DmProvider.cs @@ -109,6 +109,7 @@ namespace SqlSugar if (parameters == null || parameters.Length == 0) return null; DmParameter[] result = new DmParameter[parameters.Length]; int index = 0; + var isVarchar = this.Context.IsVarchar(); foreach (var parameter in parameters) { if (parameter.Value == null) parameter.Value = DBNull.Value; @@ -134,6 +135,10 @@ namespace SqlSugar this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName); this.OutputParameters.Add(sqlParameter); } + if (isVarchar && sqlParameter.DbType == System.Data.DbType.String) + { + sqlParameter.DbType = System.Data.DbType.AnsiString; + } ++index; } return result; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs index 023c329a0..639a017e5 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs @@ -89,6 +89,7 @@ namespace SqlSugar if (parameters == null || parameters.Length == 0) return null; MySqlParameter[] result = new MySqlParameter[parameters.Length]; int index = 0; + var isVarchar = this.Context.IsVarchar(); foreach (var parameter in parameters) { if (parameter.Value == null) parameter.Value = DBNull.Value; @@ -113,6 +114,10 @@ namespace SqlSugar this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName); this.OutputParameters.Add(sqlParameter); } + if (isVarchar && sqlParameter.DbType == System.Data.DbType.String) + { + sqlParameter.DbType = System.Data.DbType.AnsiString; + } ++index; } return result; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/SqlBuilder/MySqlInsertBuilder.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/SqlBuilder/MySqlInsertBuilder.cs index e9f6f06d7..eec51b3e7 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/SqlBuilder/MySqlInsertBuilder.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/SqlBuilder/MySqlInsertBuilder.cs @@ -30,7 +30,7 @@ namespace SqlSugar public override object FormatValue(object value) { var n = "N"; - if (this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.MySqlDisableNarvchar) + if (this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar) { n = ""; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs index dfaffa77d..03895dbc4 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs @@ -92,7 +92,7 @@ namespace SqlSugar public override object FormatValue(object value) { var n = "N"; - if (this.Context.CurrentConnectionConfig.MoreSettings != null&&this.Context.CurrentConnectionConfig.MoreSettings.MySqlDisableNarvchar) + if (this.Context.CurrentConnectionConfig.MoreSettings != null&&this.Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar) { n = ""; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/OracleProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/OracleProvider.cs index 1100af12c..8e70cfbe5 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/OracleProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/OracleProvider.cs @@ -115,6 +115,7 @@ namespace SqlSugar if (parameters == null || parameters.Length == 0) return null; OracleParameter[] result = new OracleParameter[parameters.Length]; int index = 0; + var isVarchar = this.Context.IsVarchar(); foreach (var parameter in parameters) { if (parameter.Value == null) parameter.Value = DBNull.Value; @@ -172,7 +173,10 @@ namespace SqlSugar this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName); this.OutputParameters.Add(sqlParameter); } - + if (isVarchar && sqlParameter.DbType == System.Data.DbType.String) + { + sqlParameter.DbType = System.Data.DbType.AnsiString; + } ++index; } return result; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs index cd73f4a2c..0668f157e 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs @@ -107,6 +107,7 @@ namespace SqlSugar } else { + string N = this.Context.GetN(); var type = UtilMethods.GetUnderType(value.GetType()); if (type == UtilConstants.StringType && value.ToString().Contains("{SugarSeq:=}")) { @@ -136,11 +137,11 @@ namespace SqlSugar } else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) { - return "N'" + value.ToString().ToSqlFilter() + "'"; + return N+"'" + value.ToString().ToSqlFilter() + "'"; } else { - return "N'" + value.ToString() + "'"; + return N+"'" + value.ToString() + "'"; } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs index 602322201..abb495876 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs @@ -44,6 +44,7 @@ namespace SqlSugar } else { + string N =this.Context.GetN(); var type = UtilMethods.GetUnderType(value.GetType()); if (type == UtilConstants.DateType) { @@ -69,11 +70,11 @@ namespace SqlSugar } else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) { - return "N'" + value.ToString().ToSqlFilter() + "'"; + return N + "'" + value.ToString().ToSqlFilter() + "'"; } else { - return "N'" + value.ToString() + "'"; + return N + "'" + value.ToString() + "'"; } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs index d97184328..7bcc2b5c5 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs @@ -86,6 +86,7 @@ namespace SqlSugar if (parameters == null || parameters.Length == 0) return null; NpgsqlParameter[] result = new NpgsqlParameter[parameters.Length]; int index = 0; + var isVarchar = this.Context.IsVarchar(); foreach (var parameter in parameters) { if (parameter.Value == null) parameter.Value = DBNull.Value; @@ -123,6 +124,10 @@ namespace SqlSugar this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName); this.OutputParameters.Add(sqlParameter); } + if (isVarchar && sqlParameter.DbType == System.Data.DbType.String) + { + sqlParameter.DbType = System.Data.DbType.AnsiString; + } ++index; } return result; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlServerProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlServerProvider.cs index 22b9891d5..1fcd1c025 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlServerProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlServerProvider.cs @@ -117,6 +117,7 @@ namespace SqlSugar /// public SqlParameter[] GetSqlParameter(params SugarParameter[] parameters) { + var isVarchar = this.Context.IsVarchar(); if (parameters == null || parameters.Length == 0) return null; SqlParameter[] result = new SqlParameter[parameters.Length]; int index = 0; @@ -150,6 +151,12 @@ namespace SqlSugar this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName); this.OutputParameters.Add(sqlParameter); } + + if (isVarchar&&sqlParameter.DbType== System.Data.DbType.String) + { + sqlParameter.DbType =System.Data.DbType.AnsiString; + } + ++index; } return result; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SimpleClient.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SimpleClient.cs index 85e9234d9..0fe5eee97 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SimpleClient.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SimpleClient.cs @@ -132,6 +132,10 @@ namespace SqlSugar { return this.Context.Insertable(insertObj).ExecuteReturnIdentity(); } + public virtual long InsertReturnBigIdentity(T insertObj) + { + return this.Context.Insertable(insertObj).ExecuteReturnBigIdentity(); + } public virtual bool InsertRange(T[] insertObjs) { return this.Context.Insertable(insertObjs).ExecuteCommand() > 0; @@ -238,6 +242,10 @@ namespace SqlSugar { return this.Context.Insertable(insertObj).ExecuteReturnIdentityAsync(); } + public virtual Task InsertReturnBigIdentityAsync(T insertObj) + { + return this.Context.Insertable(insertObj).ExecuteReturnBigIdentityAsync(); + } public virtual async Task InsertRangeAsync(T[] insertObjs) { return await this.Context.Insertable(insertObjs).ExecuteCommandAsync() > 0; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs index d61cfcb60..b808240c3 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs @@ -940,6 +940,11 @@ namespace SqlSugar } private void AllClientEach(Action action) { + if (this._AllClients == null) + { + this._AllClients = new List(); + this._AllClients.Add(new SugarTenant() { ConnectionConfig=this.CurrentConnectionConfig, Context=this.Context }); + } if (_AllClients.HasValue()) { foreach (var item in _AllClients.Where(it => it.Context.HasValue())) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConvert.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConvert.cs index 6b0d9dcf4..01ca518e7 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConvert.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConvert.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; namespace SqlSugar { - public static class UtilConvert + internal static class UtilConvert { public static int ObjToInt(this object thisValue) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilExtensions.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilExtensions.cs new file mode 100644 index 000000000..df0bf98e1 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilExtensions.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +namespace SqlSugar.Extensions +{ + /// + ///Common Extensions for external users + /// + public static class UtilExtensions + { + public static int ObjToInt(this object thisValue) + { + int reval = 0; + if (thisValue == null) return 0; + if (thisValue is Enum) + { + return (int)thisValue; + } + if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval)) + { + return reval; + } + return reval; + } + + public static int ObjToInt(this object thisValue, int errorValue) + { + int reval = 0; + if (thisValue is Enum) + { + return (int)thisValue; + } + if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval)) + { + return reval; + } + return errorValue; + } + + public static double ObjToMoney(this object thisValue) + { + double reval = 0; + if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval)) + { + return reval; + } + return 0; + } + + public static double ObjToMoney(this object thisValue, double errorValue) + { + double reval = 0; + if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval)) + { + return reval; + } + return errorValue; + } + + public static string ObjToString(this object thisValue) + { + if (thisValue != null) return thisValue.ToString().Trim(); + return ""; + } + + public static string ObjToString(this object thisValue, string errorValue) + { + if (thisValue != null) return thisValue.ToString().Trim(); + return errorValue; + } + + public static Decimal ObjToDecimal(this object thisValue) + { + Decimal reval = 0; + if (thisValue != null && thisValue != DBNull.Value && decimal.TryParse(thisValue.ToString(), out reval)) + { + return reval; + } + return 0; + } + + public static Decimal ObjToDecimal(this object thisValue, decimal errorValue) + { + Decimal reval = 0; + if (thisValue != null && thisValue != DBNull.Value && decimal.TryParse(thisValue.ToString(), out reval)) + { + return reval; + } + return errorValue; + } + + public static DateTime ObjToDate(this object thisValue) + { + DateTime reval = DateTime.MinValue; + if (thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out reval)) + { + reval = Convert.ToDateTime(thisValue); + } + return reval; + } + + public static DateTime ObjToDate(this object thisValue, DateTime errorValue) + { + DateTime reval = DateTime.MinValue; + if (thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out reval)) + { + return reval; + } + return errorValue; + } + + public static bool ObjToBool(this object thisValue) + { + bool reval = false; + if (thisValue != null && thisValue != DBNull.Value && bool.TryParse(thisValue.ToString(), out reval)) + { + return reval; + } + return reval; + } + } +}