Browse Source

Update pgsql subinsert datetime bug

pull/8/head
sunkaixuna 3 years ago
parent
commit
17142457ba
  1. 2
      Src/Asp.Net/PgSqlTest/Demo/Demo3_Insertable.cs
  2. 12
      Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SubInserable.cs
  3. 5
      Src/Asp.Net/SqlSugar/Realization/PostgreSQL/PostgreSQLProvider.cs

2
Src/Asp.Net/PgSqlTest/Demo/Demo3_Insertable.cs

@ -71,7 +71,7 @@ namespace OrmTest
Id = 0,
Items = new List<OrderItem>() {
new OrderItem(){
CreateTime=DateTime.Now,
OrderId=0,
Price=1,
ItemId=1

12
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;

5
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&&parameter.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;

Loading…
Cancel
Save