Update pgsql Storageable WhereColumn bug

This commit is contained in:
sunkaixuna 2021-07-19 12:35:51 +08:00
parent eb8bbdafbe
commit 109454c56c
2 changed files with 30 additions and 2 deletions

View File

@ -189,7 +189,7 @@ namespace SqlSugar
}
}
private static void SetConditList(List<StorageableInfo<T>> itemList, List<EntityColumnInfo> whereColumns, List<IConditionalModel> conditList)
private void SetConditList(List<StorageableInfo<T>> itemList, List<EntityColumnInfo> whereColumns, List<IConditionalModel> conditList)
{
;
foreach (var dataItem in itemList)
@ -202,11 +202,14 @@ namespace SqlSugar
int i = 0;
foreach (var item in whereColumns)
{
var value = item.PropertyInfo.GetValue(dataItem.Item, null);
condition.ConditionalList.Add(new KeyValuePair<WhereType, ConditionalModel>(i==0?WhereType.Or :WhereType.And, new ConditionalModel()
{
FieldName = item.DbColumnName,
ConditionalType = ConditionalType.Equal,
FieldValue = item.PropertyInfo.GetValue(dataItem.Item, null) + ""
FieldValue = value + "",
FieldValueConvertFunc=this.Context.CurrentConnectionConfig.DbType==DbType.PostgreSQL?
UtilMethods.GetTypeConvert(value):null
}));
++i;
}

View File

@ -252,6 +252,31 @@ namespace SqlSugar
return string.Format(" ({0}) {1} ", sql, shortName);
}
public static Func<string, object> GetTypeConvert(object value)
{
if (value is int || value is uint || value is int? || value is uint?)
{
return x => Convert.ToInt32(x);
}
else if (value is short || value is ushort || value is short? || value is ushort?)
{
return x => Convert.ToInt16(x);
}
else if (value is long || value is long? || value is ulong? || value is long?)
{
return x => Convert.ToInt64(x);
}
else if (value is DateTime|| value is DateTime?)
{
return x => Convert.ToDateTime(x);
}
else if (value is bool||value is bool?)
{
return x => Convert.ToBoolean(x);
}
return null;
}
internal static string GetParenthesesValue(string dbTypeName)
{
if (Regex.IsMatch(dbTypeName, @"\(.+\)"))