From c682714729f2271cfab3421812b0fbbd62707b92 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Thu, 14 Jul 2022 13:13:09 +0800 Subject: [PATCH] Adding constraints --- .../Abstract/SugarProvider/SqlSugarProvider.cs | 1 + Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs index bcec7d82e..c68bc750c 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs @@ -674,6 +674,7 @@ namespace SqlSugar #region Insertable public virtual IInsertable Insertable(T[] insertObjs) where T : class, new() { + UtilMethods.CheckArray(insertObjs); InitMappingInfo(); InsertableProvider result = this.CreateInsertable(insertObjs); return result; diff --git a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs index 196885c6b..4c6567a63 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs @@ -819,5 +819,15 @@ namespace SqlSugar return result; } + + public static void CheckArray(T[] insertObjs) where T : class, new() + { + + if (insertObjs != null && insertObjs.Length == 1 && insertObjs.FirstOrDefault().GetType().FullName.Contains("System.Collections.Generic.List`")) + { + Check.ExceptionEasy("Insertable(T []) is an array and your argument is a List", "二次封装引起的进错重载,当前方法是 Insertable(T []) 参数是一个数组,而你的参数是一个List"); + } + } + } }