mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-30 04:45:54 +08:00
PgSql Storageable bug
This commit is contained in:
parent
dbbc5f779e
commit
fb09cb7ae3
@ -14,8 +14,36 @@ namespace OrmTest
|
||||
Db.CodeFirst.InitTables<UnitSysMenu>();
|
||||
Db.DbMaintenance.TruncateTable<UnitSysMenu>();
|
||||
Db.Saveable<UnitSysMenu>(new UnitSysMenu() { ID="aa", ButtonList="", CreateName="a", CreateTime=DateTime.Now, ImageUrl="", IsDel=true, MenuCode="a", NavigateUrl="a", UpdateName="", Remark="", UpdateTime=DateTime.Now }).ExecuteReturnEntity();
|
||||
var db = Db;
|
||||
db.CodeFirst.InitTables<UinitBlukTable>();
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
List<UinitBlukTable> list2 = new List<UinitBlukTable>();
|
||||
list2.Add(new UinitBlukTable() { Id = 1, Name = "a", Create = DateTime.Now });
|
||||
list2.Add(new UinitBlukTable() { Id = 2, Name = "a", Create = DateTime.Now });
|
||||
list2.Add(new UinitBlukTable() { Id = 0, Name = "a", Create = DateTime.Now });
|
||||
db.Insertable(list2[0]).ExecuteCommand();
|
||||
var x = Db.Storageable(list2)
|
||||
.Saveable()
|
||||
.ToStorage();
|
||||
x.AsInsertable.ExecuteCommand();
|
||||
x.AsUpdateable.ExecuteCommand();
|
||||
|
||||
|
||||
db.DbMaintenance.TruncateTable<UinitBlukTable>();
|
||||
|
||||
}
|
||||
}
|
||||
internal class UinitBlukTable
|
||||
{
|
||||
public UinitBlukTable()
|
||||
{
|
||||
}
|
||||
[SugarColumn(IsPrimaryKey =true)]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DateTime Create { get; set; }
|
||||
}
|
||||
|
||||
public class BaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -336,6 +336,13 @@ namespace SqlSugar
|
||||
FieldName = this.QueryBuilder.Builder.GetTranslationColumnName(column.DbColumnName),
|
||||
FieldValue = value.ObjToString()
|
||||
});
|
||||
if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL)
|
||||
{
|
||||
data.Value.FieldValueConvertFunc = it =>
|
||||
{
|
||||
return UtilMethods.ChangeType2(it, value.GetType());
|
||||
};
|
||||
}
|
||||
cons.ConditionalList.Add(data);
|
||||
}
|
||||
if (cons.HasValue())
|
||||
|
@ -183,6 +183,29 @@ namespace SqlSugar
|
||||
}
|
||||
return returnObj;
|
||||
}
|
||||
public static object ChangeType2(object value, Type type)
|
||||
{
|
||||
if (value == null && type.IsGenericType) return Activator.CreateInstance(type);
|
||||
if (value == null) return null;
|
||||
if (type == value.GetType()) return value;
|
||||
if (type.IsEnum)
|
||||
{
|
||||
if (value is string)
|
||||
return Enum.Parse(type, value as string);
|
||||
else
|
||||
return Enum.ToObject(type, value);
|
||||
}
|
||||
if (!type.IsInterface && type.IsGenericType)
|
||||
{
|
||||
Type innerType = type.GetGenericArguments()[0];
|
||||
object innerValue = ChangeType(value, innerType);
|
||||
return Activator.CreateInstance(type, new object[] { innerValue });
|
||||
}
|
||||
if (value is string && type == typeof(Guid)) return new Guid(value as string);
|
||||
if (value is string && type == typeof(Version)) return new Version(value as string);
|
||||
if (!(value is IConvertible)) return value;
|
||||
return Convert.ChangeType(value, type);
|
||||
}
|
||||
|
||||
internal static T ChangeType<T>(T obj, Type type)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user