Browse Source

Update TableEnumIsString

pull/12/head
sunkaixuna 3 years ago
parent
commit
e9bf020ab0
  1. 9
      Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs
  2. 15
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/ConstantExpressionResolve.cs
  3. 18
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

9
Src/Asp.Net/SqlServerTest/UnitTest/UEnum.cs

@ -24,7 +24,14 @@ namespace OrmTest
db.CodeFirst.InitTables<Unit00Z1string1>();
db.Insertable(new Unit00Z1string1() { type = UnitType.a, type2 = null }).ExecuteCommand();
var x = db.Queryable<Unit00Z1string1>().Select(it => new
List<UnitType> ids = new List<UnitType>() {
UnitType.a,
UnitType.b
};
var x = db.Queryable<Unit00Z1string1>()
.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

15
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);

18
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<string> enumStringList = new List<string>();
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;

Loading…
Cancel
Save