diff --git a/Src/Asp.Net/PgSqlTest/Demo/Demo3_Insertable.cs b/Src/Asp.Net/PgSqlTest/Demo/Demo3_Insertable.cs index bcc976aa3..18fe5cf69 100644 --- a/Src/Asp.Net/PgSqlTest/Demo/Demo3_Insertable.cs +++ b/Src/Asp.Net/PgSqlTest/Demo/Demo3_Insertable.cs @@ -71,7 +71,7 @@ namespace OrmTest Id = 0, Items = new List() { new OrderItem(){ - CreateTime=DateTime.Now, + OrderId=0, Price=1, ItemId=1 diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SubInserable.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SubInserable.cs index ea925cbbb..1e7a99dc5 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SubInserable.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SubInserable.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data.SqlTypes; using System.Linq; using System.Linq.Expressions; using System.Text; @@ -243,7 +244,16 @@ namespace SqlSugar } else { - insertDictionary.Add(item.DbColumnName, item.PropertyInfo.GetValue(insetObject)); + var value = item.PropertyInfo.GetValue(insetObject); + if (value == null&&this.Context.CurrentConnectionConfig.DbType==DbType.PostgreSQL) + { + var underType= UtilMethods.GetUnderType(item.PropertyInfo.PropertyType); + if (underType == UtilConstants.DateType) + { + value = SqlDateTime.Null; + } + } + insertDictionary.Add(item.DbColumnName, value); } } return insertDictionary; diff --git a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs index 5dfd3b842..1feef0909 100644 --- a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs +++ b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs @@ -90,6 +90,11 @@ namespace SqlSugar foreach (var parameter in parameters) { if (parameter.Value == null) parameter.Value = DBNull.Value; + if(parameter.Value is System.Data.SqlTypes.SqlDateTime&¶meter.DbType==System.Data.DbType.AnsiString) + { + parameter.DbType = System.Data.DbType.DateTime; + parameter.Value = DBNull.Value; + } var sqlParameter = new NpgsqlParameter(); sqlParameter.ParameterName = parameter.ParameterName; sqlParameter.Size = parameter.Size;