From 6dcbbf51fb2d1a0d6e2d92df076d99ce1a2e431a Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 17 Dec 2022 11:48:10 +0800 Subject: [PATCH] Update sqlserver --- Src/Asp.Net/SqlServerTest/UnitTest/Main.cs | 1 + .../SqlServerTest/UnitTest/UInsert3.cs | 57 +++++++++++++++++++ .../SqlBuilder/SqlServerInsertBuilder.cs | 4 +- 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/UInsert3.cs diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs index bd7cf9858..64b4f5375 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + UInsert3.Init(); USelectTest.Init(); UnitSubToList.Init(); UnitByteArray.Init(); diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UInsert3.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UInsert3.cs new file mode 100644 index 000000000..1a948545e --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UInsert3.cs @@ -0,0 +1,57 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Data.SqlTypes; +using System.Linq; +using System.Security.Principal; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + internal class UInsert3 + { + public static void Init() + { + var db = NewUnitTest.Db; + db.Insertable(new Order() { Name = "a" }).ExecuteCommand(); + + db.Insertable(new List() { + new Order() { Name = "a" }, + new Order() { Name = "a" } + }).ExecuteCommand(); + + db.Insertable(new ORDER() { Name = "a" }).ExecuteCommand(); + } + + public class Order + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + /// + /// 姓名 + /// + public string Name { get; set; } + public decimal Price { get; set; } + [SugarColumn(InsertServerTime =true)] + public DateTime CreateTime { get; set; } + [SugarColumn(IsNullable = true)] + public int CustomId { get; set; } + } + + public class ORDER + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + /// + /// 姓名 + /// + public string Name { get; set; } + public decimal Price { get; set; } + [SugarColumn(InsertSql = "'2020-1-1'")] + public DateTime CreateTime { get; set; } + [SugarColumn(IsNullable = true)] + public int CustomId { get; set; } + } + } +} diff --git a/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerInsertBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerInsertBuilder.cs index dc942ed46..f8c20a86f 100644 --- a/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerInsertBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerInsertBuilder.cs @@ -24,7 +24,7 @@ namespace SqlSugar string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName))); if (isSingle) { - string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => Builder.SqlParameterKeyWord + it.DbColumnName)); + string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it =>base.GetDbColumn(it,Builder.SqlParameterKeyWord + it.DbColumnName))); return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString); } else @@ -57,7 +57,7 @@ namespace SqlSugar { batchInsetrSql.Append(SqlTemplateBatchUnion); } - batchInsetrSql.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), Builder.GetTranslationColumnName(it.DbColumnName))))); + batchInsetrSql.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect,base.GetDbColumn(it, FormatValue(it.Value)), Builder.GetTranslationColumnName(it.DbColumnName))))); ++i; } pageIndex++;