Jelajahi Sumber

解决pgsql 单条种子数据插入报错的问题

kenny 4 tahun lalu
induk
melakukan
af25a703e0
1 mengubah file dengan 9 tambahan dan 1 penghapusan
  1. 9 1
      Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs

+ 9 - 1
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs

@@ -179,7 +179,15 @@ public static class SqlSugarSetup
             if (seedDataTable.Columns.Contains(SqlSugarConst.PrimaryKey))
             if (seedDataTable.Columns.Contains(SqlSugarConst.PrimaryKey))
             {
             {
                 var storage = provider.Storageable(seedDataTable).WhereColumns(SqlSugarConst.PrimaryKey).ToStorage();
                 var storage = provider.Storageable(seedDataTable).WhereColumns(SqlSugarConst.PrimaryKey).ToStorage();
-                storage.AsInsertable.ExecuteCommand();
+                //如果添加一条种子数,sqlsugar默认会通过@param的方式赋值,如果PropertyType为空,则默认数据类型为字符串。插入pgsql时候会报错, 所以要忽略为空的值添加
+                if (((InsertableProvider<System.Collections.Generic.Dictionary<string, object>>)storage.AsInsertable).IsSingle)
+                {
+                    storage.AsInsertable.IgnoreColumns("UpdateTime", "UpdateUserId", "CreateUserId").ExecuteCommand();
+                }
+                else
+                {
+                    storage.AsInsertable.ExecuteCommand();
+                }
                 storage.AsUpdateable.ExecuteCommand();
                 storage.AsUpdateable.ExecuteCommand();
             }
             }
             else //没有主键或者不是预定义的主键(没主键有重复的可能)
             else //没有主键或者不是预定义的主键(没主键有重复的可能)