From 89fc5714ddc5738e0c280b3f5d5cad8e1d35f103 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Wed, 14 Jun 2017 16:30:03 +0800 Subject: [PATCH] Inset Identity Off Bug --- SqlServerTest/Demos/3_Insert.cs | 2 +- SqlServerTest/Program.cs | 2 +- SqlServerTest/UnitTest/Insert.cs | 5 +++-- SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/SqlServerTest/Demos/3_Insert.cs b/SqlServerTest/Demos/3_Insert.cs index f4b2301fb..c9e52329a 100644 --- a/SqlServerTest/Demos/3_Insert.cs +++ b/SqlServerTest/Demos/3_Insert.cs @@ -42,7 +42,7 @@ namespace OrmTest.Demo var insertObj2 = new Student() { Name = null, CreateTime = Convert.ToDateTime("2010-1-1") }; - var t9 = db.Insertable(insertObj2).Where(true/* Is insert null */, true/*off identity*/).ExecuteCommand(); + var t9 = db.Insertable(insertObj2).Where(true/* Is insert null */, false/*off identity*/).ExecuteCommand(); //Insert List var insertObjs = new List(); diff --git a/SqlServerTest/Program.cs b/SqlServerTest/Program.cs index 114e595ba..4eabd66e8 100644 --- a/SqlServerTest/Program.cs +++ b/SqlServerTest/Program.cs @@ -25,7 +25,7 @@ namespace OrmTest //new SingleQuery(1).Init(); //new SelectQuery(1).Init(); //new AutoClose(1).Init(); - //new Insert(1).Init(); + new Insert(1).Init(); //new Delete(1).Init(); //new Update(1).Init(); //new Mapping(1).Init(); diff --git a/SqlServerTest/UnitTest/Insert.cs b/SqlServerTest/UnitTest/Insert.cs index 0ccb5d3a0..e5fb874e1 100644 --- a/SqlServerTest/UnitTest/Insert.cs +++ b/SqlServerTest/UnitTest/Insert.cs @@ -89,11 +89,12 @@ new List() { var insertObj2 = new Student() { Name = null,SchoolId=0, CreateTime = Convert.ToDateTime("2010-1-1") }; var t8 = db.Insertable(insertObj2).Where(true/* Is insert null */, true/*off identity*/).ToSql(); base.Check(@"INSERT INTO [STudent] - ([SchoolId],[CreateTime]) + ([ID],[SchoolId],[CreateTime]) VALUES - (@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();", + (@ID,@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();", new List() { new SugarParameter("@SchoolId", 0), + new SugarParameter("@ID", 0), new SugarParameter("@CreateTime", Convert.ToDateTime("2010-1-1")) }, t8.Key, diff --git a/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index e6a8a3b17..37b474300 100644 --- a/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -98,7 +98,7 @@ namespace SqlSugar public IInsertable Where(bool isNoInsertNull, bool isOffIdentity = false) { - this.IsOffIdentity = IsOffIdentity; + this.IsOffIdentity = isOffIdentity; if (this.InsertBuilder.LambdaExpressions == null) this.InsertBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig); this.InsertBuilder.IsNoInsertNull = isNoInsertNull;