From 5e343ad892942894fa752dd733ce2e913ab03cea Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 26 Mar 2023 12:50:11 +0800 Subject: [PATCH] pgsql insert array null bug --- .../InsertableProvider/InsertableHelper.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableHelper.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableHelper.cs index ab6bf8d6f..ad3cd35a0 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableHelper.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableHelper.cs @@ -123,6 +123,11 @@ namespace SqlSugar if (item.IsArray) { paramters.IsArray = true; + if (item.Value == null || item.Value == DBNull.Value) + { + ArrayNull(item,paramters); + } + } if (item.Value == null && isDic) { @@ -137,6 +142,26 @@ namespace SqlSugar } } } + + private static void ArrayNull(DbColumnInfo item, SugarParameter parameter) + { + if (item.PropertyType.IsIn(typeof(Guid[]), typeof(Guid?[]))) + { + parameter.DbType = System.Data.DbType.Guid; + } + else if (item.PropertyType.IsIn(typeof(int[]), typeof(int?[]))) + { + parameter.DbType = System.Data.DbType.Int32; + } + else if (item.PropertyType.IsIn(typeof(long[]), typeof(long?[]))) + { + parameter.DbType = System.Data.DbType.Int64; + } + else if (item.PropertyType.IsIn(typeof(short[]), typeof(short?[]))) + { + parameter.DbType = System.Data.DbType.Int16; + } + } internal void Init() { InsertBuilder.EntityInfo = this.EntityInfo;