diff --git a/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj b/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj index 35129a2fb..303b3bf3a 100644 --- a/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj +++ b/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj @@ -103,6 +103,7 @@ + diff --git a/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs b/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs index 44cc3476e..840d3cc37 100644 --- a/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs +++ b/Src/Asp.Net/PgSqlTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + UInsert3.Init(); UnitSubToList.Init(); UnitByteArray.Init(); Unit001.Init(); diff --git a/Src/Asp.Net/PgSqlTest/UnitTest/UInsert3.cs b/Src/Asp.Net/PgSqlTest/UnitTest/UInsert3.cs new file mode 100644 index 000000000..1a948545e --- /dev/null +++ b/Src/Asp.Net/PgSqlTest/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/PostgreSQL/SqlBuilder/PostgreSQLInsertBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLInsertBuilder.cs index 87630a7ef..a14e9b234 100644 --- a/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLInsertBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLInsertBuilder.cs @@ -47,7 +47,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))); ActionMinDate(); return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString); } @@ -75,6 +75,10 @@ namespace SqlSugar } batchInsetrSql.Append("\r\n ( " + string.Join(",", columns.Select(it => { + if (it.InsertServerTime || it.InsertSql.HasValue()) + { + return GetDbColumn(it, null); + } object value = null; if (it.Value is DateTime) {