diff --git a/Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite b/Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite index f8d799139..81c2453d8 100644 Binary files a/Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite and b/Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite differ diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs index 6a3ba335e..ce80a3768 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs @@ -52,7 +52,7 @@ namespace SqlSugar private static readonly MethodInfo getConvertGuid = typeof(IDataRecordExtensions).GetMethod("GetConvertGuid"); private static readonly MethodInfo getConvertInt16 = typeof(IDataRecordExtensions).GetMethod("GetConvertInt16"); private static readonly MethodInfo getConvertInt32 = typeof(IDataRecordExtensions).GetMethod("GetConvertInt32"); - private static readonly MethodInfo getConvetInt64 = typeof(IDataRecordExtensions).GetMethod("GetConvetInt64"); + private static readonly MethodInfo getConvertInt64 = typeof(IDataRecordExtensions).GetMethod("GetConvetInt64"); private static readonly MethodInfo getConvertEnum_Null = typeof(IDataRecordExtensions).GetMethod("GetConvertEnum_Null"); private static readonly MethodInfo getOtherNull = typeof(IDataRecordExtensions).GetMethod("GetOtherNull"); private static readonly MethodInfo getOther = typeof(IDataRecordExtensions).GetMethod("GetOther"); @@ -218,8 +218,10 @@ namespace SqlSugar { case CSharpDataType.@int: CheckType(bind.IntThrow, bindProperyTypeName, validPropertyName, propertyName); - if (bindProperyTypeName.IsContainsIn("int", "int32", "int64")) + if (bindProperyTypeName.IsContainsIn("int", "int32")) method = isNullableType ? getConvertInt32 : getInt32; + if (bindProperyTypeName.IsContainsIn("int64")) + method = isNullableType ? getConvertInt64 : getInt64; break; case CSharpDataType.@bool: if (bindProperyTypeName == "bool" || bindProperyTypeName == "boolean") @@ -267,7 +269,7 @@ namespace SqlSugar break; case CSharpDataType.@long: if (bindProperyTypeName == "int64" || bindProperyTypeName == "long") - method = isNullableType ? getConvetInt64 : getInt64; + method = isNullableType ? getConvertInt64 : getInt64; break; default: method = getValueMethod; diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs index d6d25ca95..bb2eec79d 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs @@ -227,6 +227,7 @@ namespace SqlSugar result = "DateTime.Now"; } result = result.Replace("\r", "\t").Replace("\n", "\t"); + result = result.IsIn("''","\"\"") ? string.Empty : result; return result; } private string GetPropertyText(DbColumnInfo item, string PropertyText) diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 2b1cf0c6a..d735963f5 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -117,7 +117,8 @@ namespace SqlSugar } public virtual ISugarQueryable Where(string whereString, object whereObj = null) { - this.Where(whereString, whereObj); + if (whereString.IsValuable()) + this.Where(whereString, whereObj); return this; } public virtual ISugarQueryable Where(string whereString, object whereObj = null) @@ -793,7 +794,7 @@ namespace SqlSugar #region Order public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { - _OrderBy(expression,type); + _OrderBy(expression, type); return this; } @@ -876,19 +877,19 @@ namespace SqlSugar #endregion #region Aggr - public TResult Max(Expression> expression) - { - return _Max(expression); - } - public TResult Min(Expression> expression) - { - return _Min(expression); - } - public TResult Sum(Expression> expression) - { - return _Sum(expression); - } - public TResult Avg(Expression> expression) + public TResult Max(Expression> expression) + { + return _Max(expression); + } + public TResult Min(Expression> expression) + { + return _Min(expression); + } + public TResult Sum(Expression> expression) + { + return _Sum(expression); + } + public TResult Avg(Expression> expression) { return _Avg(expression); } @@ -1024,19 +1025,19 @@ namespace SqlSugar #endregion #region Aggr - public TResult Max(Expression> expression) - { - return _Max(expression); - } - public TResult Min(Expression> expression) - { - return _Min(expression); - } - public TResult Sum(Expression> expression) - { - return _Sum(expression); - } - public TResult Avg(Expression> expression) + public TResult Max(Expression> expression) + { + return _Max(expression); + } + public TResult Min(Expression> expression) + { + return _Min(expression); + } + public TResult Sum(Expression> expression) + { + return _Sum(expression); + } + public TResult Avg(Expression> expression) { return _Avg(expression); } @@ -1198,19 +1199,19 @@ namespace SqlSugar #endregion #region Aggr - public TResult Max(Expression> expression) - { - return _Max(expression); - } - public TResult Min(Expression> expression) - { - return _Min(expression); - } - public TResult Sum(Expression> expression) - { - return _Sum(expression); - } - public TResult Avg(Expression> expression) + public TResult Max(Expression> expression) + { + return _Max(expression); + } + public TResult Min(Expression> expression) + { + return _Min(expression); + } + public TResult Sum(Expression> expression) + { + return _Sum(expression); + } + public TResult Avg(Expression> expression) { return _Avg(expression); } @@ -1398,20 +1399,20 @@ namespace SqlSugar #endregion #region Aggr - public TResult Max(Expression> expression) - { - return _Max(expression); - } - public TResult Min(Expression> expression) - { - return _Min(expression); - } - public TResult Sum(Expression> expression) - { - return _Sum(expression); - } - public TResult Avg(Expression> expression) - { + public TResult Max(Expression> expression) + { + return _Max(expression); + } + public TResult Min(Expression> expression) + { + return _Min(expression); + } + public TResult Sum(Expression> expression) + { + return _Sum(expression); + } + public TResult Avg(Expression> expression) + { return _Avg(expression); } #endregion @@ -1625,19 +1626,19 @@ namespace SqlSugar #endregion #region Aggr - public TResult Max(Expression> expression) - { - return _Max(expression); - } - public TResult Min(Expression> expression) - { - return _Min(expression); - } - public TResult Sum(Expression> expression) - { - return _Sum(expression); - } - public TResult Avg(Expression> expression) + public TResult Max(Expression> expression) + { + return _Max(expression); + } + public TResult Min(Expression> expression) + { + return _Min(expression); + } + public TResult Sum(Expression> expression) + { + return _Sum(expression); + } + public TResult Avg(Expression> expression) { return _Avg(expression); } @@ -1878,19 +1879,19 @@ namespace SqlSugar #endregion #region Aggr - public TResult Max(Expression> expression) - { - return _Max(expression); - } - public TResult Min(Expression> expression) - { - return _Min(expression); - } - public TResult Sum(Expression> expression) - { - return _Sum(expression); - } - public TResult Avg(Expression> expression) + public TResult Max(Expression> expression) + { + return _Max(expression); + } + public TResult Min(Expression> expression) + { + return _Min(expression); + } + public TResult Sum(Expression> expression) + { + return _Sum(expression); + } + public TResult Avg(Expression> expression) { return _Avg(expression); } diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs index a2e12a61d..4f63df451 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/Method/DefaultDbMethod.cs @@ -270,5 +270,10 @@ namespace SqlSugar { return "( 1 = 2 ) "; } + + public string GuidNew() + { + return "'"+Guid.NewGuid()+"' "; + } } } diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/Method/IDbMethods.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/Method/IDbMethods.cs index c91dc1a0e..0e6cca3ce 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/Method/IDbMethods.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/Method/IDbMethods.cs @@ -49,5 +49,6 @@ namespace SqlSugar string MappingColumn(MethodCallExpressionModel model); string True(); string False(); + string GuidNew(); } } diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs index bab23d6a2..b61526a3c 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs @@ -235,6 +235,20 @@ namespace SqlSugar }; return methodCallExpressionArgs; } + + protected string GetNewExpressionValue(Expression item) + { + var newContext = this.Context.GetCopyContext(); + newContext.Resolve(item, this.Context.IsJoin ? ResolveExpressType.WhereMultiple : ResolveExpressType.WhereSingle); + this.Context.Index = newContext.Index; + this.Context.ParameterIndex = newContext.ParameterIndex; + if (newContext.Parameters.IsValuable()) + { + this.Context.Parameters.AddRange(newContext.Parameters); + } + return newContext.Result.GetResultString(); + } + protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string asName) { if (item.NodeType == ExpressionType.Constant) diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs index 4157d32f7..0e0811bd9 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/MemberInitExpressionResolve.cs @@ -49,7 +49,13 @@ namespace SqlSugar MemberAssignment memberAssignment = (MemberAssignment)binding; var memberName = memberAssignment.Member.Name; var item = memberAssignment.Expression; - if (item is UnaryExpression||item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant) + if ((item is MemberExpression) && ((MemberExpression)item).Expression == null) + { + var paramterValue = ExpressionTool.DynamicInvoke(item); + string parameterName = AppendParameter(paramterValue); + this.Context.Result.Append(base.Context.GetEqString(memberName, parameterName)); + } + else if (item is UnaryExpression || item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant) { base.Expression = item; base.Start(); @@ -80,7 +86,8 @@ namespace SqlSugar } else if (item is BinaryExpression) { - Check.ThrowNotSupportedException(item.GetType().Name); + var result=GetNewExpressionValue(item); + this.Context.Result.Append(base.Context.GetEqString(memberName, result)); } } } diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs index 50f91dbf6..e77659b19 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs @@ -14,13 +14,18 @@ namespace SqlSugar var express = base.Expression as MethodCallExpression; var isLeft = parameter.IsLeft; string methodName = express.Method.Name; - if (methodName == "get_Item") { - string paramterName =this.Context.SqlParameterKeyWord+ExpressionConst.Const + this.Context.ParameterIndex; + if (methodName == "get_Item") + { + string paramterName = this.Context.SqlParameterKeyWord + ExpressionConst.Const + this.Context.ParameterIndex; this.Context.Parameters.Add(new SugarParameter(paramterName, ExpressionTool.DynamicInvoke(express))); - this.Context.Result.Append(string.Format(" {0} ",paramterName)); + this.Context.Result.Append(string.Format(" {0} ", paramterName)); this.Context.ParameterIndex++; return; } + else if (methodName == "NewGuid") { + this.Context.Result.Append(this.Context.DbMehtods.GuidNew()); + return; + } var isValidNativeMethod = MethodMapping.ContainsKey(methodName)&&express.Method.DeclaringType.Namespace==("System"); if (!isValidNativeMethod&&express.Method.DeclaringType.Namespace.IsIn("System.Linq", "System.Collections.Generic")&&methodName=="Contains") { methodName = "ContainsArray"; diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Properties/AssemblyInfo.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Properties/AssemblyInfo.cs index 919d70691..c23612b83 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Properties/AssemblyInfo.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/Properties/AssemblyInfo.cs @@ -17,5 +17,5 @@ using System.Runtime.InteropServices; // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("1c022a5c-4e4d-4026-a8a3-f659b9740a1a")] -[assembly: AssemblyVersion("4.2.0.3")] -[assembly: AssemblyFileVersion("4.2.0.3")] +[assembly: AssemblyVersion("4.2.0.4")] +[assembly: AssemblyFileVersion("4.2.0.4")] diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarClient.cs b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarClient.cs index 8a0643283..a58579e07 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarClient.cs @@ -224,6 +224,25 @@ namespace SqlSugar queryable.Where(joinExpression); return queryable; } + public virtual List UnionAll(params ISugarQueryable[] queryables) where T : class, new() + { + if (queryables.IsNullOrEmpty()) return new List(); + List result = new List(); + foreach (var item in queryables) + { + var addItems = item.ToList(); + if (addItems.IsValuable()) + { + result.AddRange(addItems); + } + } + return result; + } + public virtual List UnionAll(List> queryables) where T : class, new() + { + if (queryables.IsNullOrEmpty()) return new List(); + return UnionAll(queryables.ToArray()); + } #endregion #region Insertable @@ -259,7 +278,7 @@ namespace SqlSugar { return this.Deleteable().In(primaryKeyValue); } - public virtual IDeleteable Deleteable(dynamic [] primaryKeyValues) where T : class, new() + public virtual IDeleteable Deleteable(dynamic[] primaryKeyValues) where T : class, new() { return this.Deleteable().In(primaryKeyValues); } @@ -383,7 +402,8 @@ namespace SqlSugar { get { - if (_SimpleClient == null) { + if (_SimpleClient == null) + { _SimpleClient = new SimpleClient(this); } return _SimpleClient; diff --git a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarForCore.nuspec b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarForCore.nuspec index de8674912..f2afd2ffd 100644 --- a/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarForCore.nuspec +++ b/Src/Asp.NetCore/SqlServerTest/src/SqlSugar/SqlSugarForCore.nuspec @@ -2,7 +2,7 @@ sqlSugarCore - 4.2.0.3 + 4.2.0.4 sunkaixuan Landa http://www.apache.org/licenses/LICENSE-2.0.html