Update enum

This commit is contained in:
sunkaixuna
2021-12-29 21:22:34 +08:00
parent 8fb4b46265
commit d9382a1fd9
17 changed files with 70 additions and 14 deletions

View File

@@ -606,7 +606,15 @@ namespace SqlSugar
};
if (columnInfo.PropertyType.IsEnum())
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{
columnInfo.Value = columnInfo.Value.ToString();
columnInfo.PropertyType = UtilConstants.StringType;
}
else
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
}
}
insertItem.Add(columnInfo);
}

View File

@@ -208,7 +208,14 @@ namespace SqlSugar
var value = item.PropertyInfo.GetValue(dataItem.Item, null);
if (value != null&&value.GetType().IsEnum())
{
value = Convert.ToInt64(value);
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{
value = value.ToString();
}
else
{
value = Convert.ToInt64(value);
}
}
condition.ConditionalList.Add(new KeyValuePair<WhereType, ConditionalModel>(i==0?WhereType.Or :WhereType.And, new ConditionalModel()
{
@@ -228,6 +235,7 @@ namespace SqlSugar
ILambdaExpressions resolveExpress = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig); ;
if (this.Context.CurrentConnectionConfig.MoreSettings != null)
{
resolveExpress.TableEnumIsString = this.Context.CurrentConnectionConfig.MoreSettings.TableEnumIsString;
resolveExpress.PgSqlIsAutoToLower = this.Context.CurrentConnectionConfig.MoreSettings.PgSqlIsAutoToLower;
}
else

View File

@@ -147,6 +147,7 @@ namespace SqlSugar
this.LambdaExpressions.Clear();
if (this.Context.CurrentConnectionConfig.MoreSettings != null)
{
resolveExpress.TableEnumIsString = this.Context.CurrentConnectionConfig.MoreSettings.TableEnumIsString;
resolveExpress.PgSqlIsAutoToLower = this.Context.CurrentConnectionConfig.MoreSettings.PgSqlIsAutoToLower;
}
else

View File

@@ -102,6 +102,7 @@ namespace SqlSugar
this.LambdaExpressions.Clear();
if (this.Context.CurrentConnectionConfig.MoreSettings != null)
{
resolveExpress.TableEnumIsString = this.Context.CurrentConnectionConfig.MoreSettings.TableEnumIsString;
resolveExpress.PgSqlIsAutoToLower = this.Context.CurrentConnectionConfig.MoreSettings.PgSqlIsAutoToLower;
}
else
@@ -198,7 +199,7 @@ namespace SqlSugar
{
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{
return value.ToString();
return value.ToSqlValue();
}
else
{

View File

@@ -234,6 +234,7 @@ namespace SqlSugar
this.LambdaExpressions.Clear();
if (this.Context.CurrentConnectionConfig.MoreSettings != null)
{
resolveExpress.TableEnumIsString = this.Context.CurrentConnectionConfig.MoreSettings.TableEnumIsString;
resolveExpress.PgSqlIsAutoToLower = this.Context.CurrentConnectionConfig.MoreSettings.PgSqlIsAutoToLower;
}
else

View File

@@ -121,6 +121,7 @@ namespace SqlSugar
if (this.Context.CurrentConnectionConfig.MoreSettings != null)
{
resolveExpress.PgSqlIsAutoToLower = this.Context.CurrentConnectionConfig.MoreSettings.PgSqlIsAutoToLower;
resolveExpress.TableEnumIsString = this.Context.CurrentConnectionConfig.MoreSettings.TableEnumIsString;
}
else
{
@@ -306,7 +307,7 @@ namespace SqlSugar
{
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{
return value.ToString();
return value.ToSqlValue();
}
else
{

View File

@@ -551,7 +551,15 @@ namespace SqlSugar
};
if (columnInfo.PropertyType.IsEnum())
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{
columnInfo.PropertyType = UtilConstants.StringType;
columnInfo.Value = columnInfo.Value.ToString();
}
else
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
}
}
updateItem.Add(columnInfo);
}

View File

@@ -53,11 +53,21 @@ namespace SqlSugar
}
}
public static object GetValue(object value)
public static object GetValue(object value,ExpressionContext context)
{
if (value == null) return value;
var type = value.GetType();
if (type.IsEnum() && type != typeof(DateType) && type != typeof(JoinType) && type != typeof(OrderByType)) return Convert.ToInt64(value);
if (type.IsEnum() && type != typeof(DateType) && type != typeof(JoinType) && type != typeof(OrderByType))
{
if (context.TableEnumIsString == true)
{
return value.ToString();
}
else
{
return Convert.ToInt64(value);
}
}
else
return value;
}

View File

@@ -44,6 +44,7 @@ namespace SqlSugar
public MappingTableList MappingTables { get; set; }
public IgnoreColumnList IgnoreComumnList { get; set; }
public bool PgSqlIsAutoToLower { get; set; }
public bool? TableEnumIsString { get; set; }
public List<SqlFuncExternal> SqlFuncServices { get; set; }
public Expression RootExpression { get; set; }
public bool IsSingle
@@ -131,6 +132,7 @@ namespace SqlSugar
copyContext.PgSqlIsAutoToLower = this.PgSqlIsAutoToLower;
copyContext.IsSingle = this.IsSingle;
copyContext.RootExpression = this.RootExpression;
copyContext.TableEnumIsString = this.TableEnumIsString;
return copyContext;
}
public ExpressionContext GetCopyContextWithMapping()
@@ -145,6 +147,7 @@ namespace SqlSugar
copyContext.InitMappingInfo = this.InitMappingInfo;
copyContext.RefreshMapping = this.RefreshMapping;
copyContext.PgSqlIsAutoToLower = this.PgSqlIsAutoToLower;
copyContext.TableEnumIsString = this.TableEnumIsString;
copyContext.IsSingle = this.IsSingle;
copyContext.RootExpression = this.RootExpression;
return copyContext;

View File

@@ -225,7 +225,14 @@ namespace SqlSugar
Context.ParameterIndex++;
if (value != null && value.GetType().IsEnum())
{
value = Convert.ToInt64(value);
if (this.Context.TableEnumIsString == true)
{
value = value.ToString();
}
else
{
value = Convert.ToInt64(value);
}
}
this.Context.Parameters.Add(new SugarParameter(appendValue, value));
appendValue = string.Format(" {0} ", appendValue);

View File

@@ -12,7 +12,7 @@ namespace SqlSugar
{
var expression = base.Expression as ConstantExpression;
var isLeft = parameter.IsLeft;
object value = ExpressionTool.GetValue(expression.Value);
object value = ExpressionTool.GetValue(expression.Value,this.Context);
var baseParameter = parameter.BaseParameter;
baseParameter.ChildExpression = expression;
var isSetTempData = baseParameter.CommonTempData.HasValue() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result);

View File

@@ -28,6 +28,7 @@ namespace SqlSugar
Action RefreshMapping { get; set; }
bool PgSqlIsAutoToLower { get; set; }
Expression RootExpression { get; set; }
bool? TableEnumIsString { get; set; }
string GetAsString(string fieldName, string fieldValue);
void Resolve(Expression expression, ResolveExpressType resolveType);

View File

@@ -59,7 +59,7 @@ namespace SqlSugar
{
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{
return value.ToString();
return value.ToSqlValue(); ;
}
else
{

View File

@@ -121,7 +121,7 @@ namespace SqlSugar
{
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{
return value.ToString();
return value.ToSqlValue();
}
else
{

View File

@@ -65,7 +65,14 @@ namespace SqlSugar
}
else if (type.IsEnum())
{
return Convert.ToInt64(value);
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{
return value.ToSqlValue();
}
else
{
return Convert.ToInt64(value);
}
}
else if (type == UtilConstants.BoolType)
{

View File

@@ -101,7 +101,7 @@ namespace SqlSugar
{
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{
return value.ToString();
return value.ToSqlValue();
}
else
{

View File

@@ -63,7 +63,7 @@ namespace SqlSugar
{
if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
{
return value.ToString();
return value.ToSqlValue();
}
else
{