diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs index 978bc7b19..3c7154c45 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs @@ -24,7 +24,14 @@ namespace OrmTest db.CodeFirst.InitTables(); db.Insertable(new Unit00Z1string1() { type = UnitType.a, type2 = null }).ExecuteCommand(); - var x = db.Queryable().Select(it => new + List ids = new List() { + UnitType.a, + UnitType.b + }; + var x = db.Queryable() + .Where(it => it.type == UnitType.b) + .Where(it=>it.type2== UnitType.b) + .Where(it=> ids.Contains(it.type)).Select(it => new { x = it.type, x2 = it.type2 diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs index 948de6eac..d32a34ab9 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs @@ -13,6 +13,21 @@ namespace SqlSugar var expression = base.Expression as ConstantExpression; var isLeft = parameter.IsLeft; object value = ExpressionTool.GetValue(expression.Value,this.Context); + if (this.Context.TableEnumIsString == true + && value != null + && value.IsInt() + && base.BaseParameter?.OppsiteExpression != null) + { + if (base.BaseParameter?.OppsiteExpression is UnaryExpression) + { + var oppsiteExpression = base.BaseParameter?.OppsiteExpression as UnaryExpression; + var oppsiteValue = oppsiteExpression.Operand; + if (oppsiteValue.Type.IsEnum()) + { + value = UtilMethods.ChangeType2(value, oppsiteValue.Type).ToString(); + } + } + } var baseParameter = parameter.BaseParameter; baseParameter.ChildExpression = expression; var isSetTempData = baseParameter.CommonTempData.HasValue() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result); diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs index 5569d127d..b96470917 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs @@ -678,6 +678,24 @@ namespace SqlSugar model.Args[0].MemberValue = first.Value; } } + if (this.Context.TableEnumIsString == true) + { + List enumStringList = new List(); + foreach (var inItem in (model.Args[0].MemberValue as IEnumerable)) + { + if (inItem != null) + { + if (UtilMethods.GetUnderType(inItem.GetType()).IsEnum()) + { + enumStringList.Add(inItem.ToString()); + } + } + } + if (enumStringList.Any()) + { + model.Args[0].MemberValue = enumStringList; + } + } var caResult = this.Context.DbMehtods.ContainsArray(model); this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString()); return caResult;