Update core

This commit is contained in:
sunkaixuna
2021-12-29 21:37:33 +08:00
parent 68c5f60d3e
commit 6fbea446b9
20 changed files with 140 additions and 18 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);
}
@@ -647,7 +655,15 @@ namespace SqlSugar
}
if (columnInfo.PropertyType.IsEnum()&& columnInfo.Value!=null)
{
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);
}
}
if (column.IsJson&& columnInfo.Value!=null)
{

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
@@ -196,7 +197,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

@@ -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
{
@@ -304,7 +305,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

@@ -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);
}
@@ -572,7 +580,15 @@ namespace SqlSugar
};
if (columnInfo.PropertyType.IsEnum()&& columnInfo.Value!=null)
{
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);
}
}
if (column.IsJson)
{

View File

@@ -13,5 +13,6 @@ namespace SqlSugar
public bool DisableNvarchar { get; set; }
public bool PgSqlIsAutoToLower = true;
public int DefaultCacheDurationInSeconds { get; set; }
public bool? TableEnumIsString { get; set; }
}
}

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

@@ -60,7 +60,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.ByteArrayType)
{

View File

@@ -57,7 +57,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

@@ -119,7 +119,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

@@ -17,7 +17,7 @@ namespace SqlSugar
{
sql = sql.Replace("+@", "+:");
if (sql.HasValue()&&sql.Contains("@")) {
var exceptionalCaseInfo = Regex.Matches(sql, @"\'.*?\@.*?\'| [\.,\w]+\@[\.,\w]+ | [\.,\w]+\@[\.,\w]+");
var exceptionalCaseInfo = Regex.Matches(sql, @"\'[^\=]*?\@.*?\'| [\.,\w]+\@[\.,\w]+ | [\.,\w]+\@[\.,\w]+|[\.,\w]+\@[\.,\w]+ ");
if (exceptionalCaseInfo != null) {
foreach (var item in exceptionalCaseInfo.Cast<Match>())
{

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

@@ -99,7 +99,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.ByteArrayType)
{

View File

@@ -61,7 +61,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.ByteArrayType)
{