Browse Source

Update core

pull/12/head
sunkaixuna 3 years ago
parent
commit
6b7a0433e8
  1. 7
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/Reportable/ReportableProvider.cs
  2. 1
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs
  3. 8
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs
  4. 1
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConditionalModel.cs
  5. 19
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IStorageable.cs
  6. 51
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs

7
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/Reportable/ReportableProvider.cs

@ -205,7 +205,12 @@ namespace SqlSugar
}
else if (type.IsIn(typeof(decimal), typeof(double)))
{
return value;
Expression<Func<SingleColumnEntity<object>, object>> exp = it => Convert.ToDecimal(it.ColumnName);
var result = queryBuilder.GetExpressionValue(exp, ResolveExpressType.WhereSingle).GetResultString();
result = Regex.Replace(result, @"\[ColumnName\]", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"\`ColumnName\`", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"""ColumnName""", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase);
return result;
}
else if (type.IsIn(typeof(DateTime)))
{

1
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs

@ -221,6 +221,7 @@ namespace SqlSugar
{
FieldName = item.DbColumnName,
ConditionalType = ConditionalType.Equal,
CSharpTypeName=UtilMethods.GetTypeName(value),
FieldValue = value + "",
FieldValueConvertFunc=this.Context.CurrentConnectionConfig.DbType==DbType.PostgreSQL?
UtilMethods.GetTypeConvert(value):null

8
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs

@ -363,9 +363,17 @@ namespace SqlSugar
private static object GetFieldValue(ConditionalModel item)
{
if (item.FieldValueConvertFunc != null)
{
return item.FieldValueConvertFunc(item.FieldValue);
}
else if (item.CSharpTypeName.HasValue())
{
return UtilMethods.ConvertDataByTypeName(item.CSharpTypeName,item.FieldValue);
}
else
{
return item.FieldValue;
}
}
#endregion

1
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConditionalModel.cs

@ -24,6 +24,7 @@ namespace SqlSugar
}
public string FieldName { get; set; }
public string FieldValue { get; set; }
public string CSharpTypeName { get; set; }
public ConditionalType ConditionalType { get; set; }
[Newtonsoft.Json.JsonIgnoreAttribute]
public Func<string,object> FieldValueConvertFunc { get; set; }

19
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IStorageable.cs

@ -38,10 +38,27 @@ namespace SqlSugar
var list = Database.Where(it=>true);
foreach (var pk in PkFields)
{
list = list.Where(it => it.GetType().GetProperty(pk).GetValue(it, null).ObjToString() == Item.GetType().GetProperty(pk).GetValue(Item, null).ObjToString());
list = list.Where(it =>IsEquals(it, pk));
}
return list.Any();
}
private bool IsEquals(T it, string pk)
{
var leftValue = it.GetType().GetProperty(pk).GetValue(it, null);
var rightValue = Item.GetType().GetProperty(pk).GetValue(Item, null);
var left = leftValue.ObjToString();
var rigth = rightValue.ObjToString();
if (it.GetType().GetProperty(pk).PropertyType == UtilConstants.DecType)
{
return Convert.ToDecimal(leftValue) == Convert.ToDecimal(rightValue);
}
else
{
return left == rigth;
}
}
public bool NotAny()
{
return !Any();

51
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs

@ -286,6 +286,18 @@ namespace SqlSugar
return null;
}
internal static string GetTypeName(object value)
{
if (value == null)
{
return null;
}
else
{
return value.GetType().Name;
}
}
internal static string GetParenthesesValue(string dbTypeName)
{
if (Regex.IsMatch(dbTypeName, @"\(.+\)"))
@ -438,5 +450,44 @@ namespace SqlSugar
}
return dic;
}
public static object ConvertDataByTypeName(string ctypename,string value)
{
var item = new ConditionalModel() {
CSharpTypeName = ctypename,
FieldValue = value
};
if (item.CSharpTypeName.EqualCase(UtilConstants.DecType.Name))
{
return Convert.ToDecimal(item.FieldValue);
}
else if (item.CSharpTypeName.EqualCase(UtilConstants.DobType.Name))
{
return Convert.ToDouble(item.FieldValue);
}
else if (item.CSharpTypeName.EqualCase(UtilConstants.DateType.Name))
{
return Convert.ToDateTime(item.FieldValue);
}
else if (item.CSharpTypeName.EqualCase(UtilConstants.IntType.Name))
{
return Convert.ToInt32(item.FieldValue);
}
else if (item.CSharpTypeName.EqualCase(UtilConstants.LongType.Name))
{
return Convert.ToInt64(item.FieldValue);
}
else if (item.CSharpTypeName.EqualCase(UtilConstants.ShortType.Name))
{
return Convert.ToInt16(item.FieldValue);
}
else if (item.CSharpTypeName.EqualCase(UtilConstants.DateTimeOffsetType.Name))
{
return UtilMethods.GetDateTimeOffsetByDateTime(Convert.ToDateTime(item.FieldValue));
}
else
{
return item.FieldValue;
}
}
}
}

Loading…
Cancel
Save