From 8677e769c11ce805d290581ed7c7f0dc840fd60d Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 26 May 2017 14:31:19 +0800 Subject: [PATCH] - --- OrmTest/UnitTest/Delete.cs | 10 +++---- OrmTest/UnitTest/Insert.cs | 27 +++++++++---------- .../SqlBuilder/DMLBuilder/DeleteBuilder.cs | 2 +- .../DeleteProvider/DeleteableProvider.cs | 4 +-- SqlSugar/SqlSugarAccessory.cs | 6 +++++ 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/OrmTest/UnitTest/Delete.cs b/OrmTest/UnitTest/Delete.cs index 5f39c908d..04349b4c1 100644 --- a/OrmTest/UnitTest/Delete.cs +++ b/OrmTest/UnitTest/Delete.cs @@ -22,14 +22,14 @@ namespace OrmTest var db = GetInstance(); //by entity var t1= db.Deleteable().Where(new Student() { Id = 1 }).ToSql(); - base.Check(@"DELETE FROM [Student] WHERE Id IN ('1') ", + base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1') ", null, t1.Key, null, "Delte t1 error" ); //use lock var t2 = db.Deleteable().With(SqlWith.RowLock).ToSql(); - base.Check(@"DELETE FROM [Student] WITH(ROWLOCK) ", + base.Check(@"DELETE FROM [STudent] WITH(ROWLOCK) ", null, t2.Key, null, "Delte t2 error" @@ -37,18 +37,18 @@ namespace OrmTest //by primary key var t3 = db.Deleteable().In(1).ToSql(); - base.Check(@"DELETE FROM [Student] WHERE Id IN ('1') ", + base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1') ", null, t3.Key, null, "Delte tt error" ); //by primary key array var t4 = db.Deleteable().In(new int[] { 1,2}).ToSql(); - base.Check(@"DELETE FROM [Student] WHERE Id IN ('1','2') ", null, t4.Key, null, "Update t4 error"); + base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1','2') ", null, t4.Key, null, "Update t4 error"); //by expression var t5 = db.Deleteable().Where(it=>it.Id==1).ToSql(); - base.Check(@"DELETE FROM [Student] WHERE ( [Id] = @Id0 ) ", new List() { + base.Check(@"DELETE FROM [STudent] WHERE ( [ID] = @Id0 ) ", new List() { new SugarParameter("@Id0",1) }, t5.Key, t5.Value, "Delte t5 error"); } diff --git a/OrmTest/UnitTest/Insert.cs b/OrmTest/UnitTest/Insert.cs index b85e73018..dd7b59915 100644 --- a/OrmTest/UnitTest/Insert.cs +++ b/OrmTest/UnitTest/Insert.cs @@ -24,7 +24,7 @@ namespace OrmTest.UnitTest //db.MappingColumns.Add("id","dbid", "Student"); var t1 = db.Insertable(insertObj).ToSql(); - base.Check(@"INSERT INTO [Student] + base.Check(@"INSERT INTO [STudent] ([SchoolId],[Name],[CreateTime]) VALUES (@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();", @@ -42,7 +42,7 @@ namespace OrmTest.UnitTest db.IgnoreColumns = null; //Only insert Name var t3 = db.Insertable(insertObj).InsertColumns(it => new { it.Name }).ToSql(); - base.Check(@"INSERT INTO [Student] + base.Check(@"INSERT INTO [STudent] ([Name]) VALUES (@Name) ;SELECT SCOPE_IDENTITY();", new List() { @@ -52,7 +52,7 @@ namespace OrmTest.UnitTest //Ignore Name and TestId var t4 = db.Insertable(insertObj).IgnoreColumns(it => new { it.Name, it.TestId }).ToSql(); - base.Check(@"INSERT INTO [Student] + base.Check(@"INSERT INTO [STudent] ([SchoolId],[CreateTime]) VALUES (@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();", @@ -64,7 +64,7 @@ namespace OrmTest.UnitTest //Ignore Name and TestId var t5 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql(); - base.Check(@"INSERT INTO [Student] WITH(UPDLOCK) + base.Check(@"INSERT INTO [STudent] WITH(UPDLOCK) ([SchoolId],[CreateTime]) VALUES (@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();", @@ -75,29 +75,26 @@ new List() { ); //Use Lock var t6 = db.Insertable(insertObj).With(SqlWith.UpdLock).ToSql(); - base.Check(@"INSERT INTO [Student] WITH(UPDLOCK) - ([SchoolId],[Name],[CreateTime],[TestId]) + base.Check(@"INSERT INTO [STudent] WITH(UPDLOCK) + ([SchoolId],[Name],[CreateTime]) VALUES - (@SchoolId,@Name,@CreateTime,@TestId) ;SELECT SCOPE_IDENTITY();", + (@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();", new List() { new SugarParameter("@SchoolId",0), new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")), - new SugarParameter("@Name","jack"), - new SugarParameter("@TestId",0) + new SugarParameter("@Name","jack") }, t6.Key, t6.Value, "Insert t6 error" ); 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],[TestId]) + base.Check(@"INSERT INTO [STudent] + ([SchoolId],[CreateTime]) VALUES - (@SchoolId,@CreateTime,@TestId) ;SELECT SCOPE_IDENTITY();", + (@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();", new List() { new SugarParameter("@SchoolId", 0), - new SugarParameter("@CreateTime", Convert.ToDateTime("2010-1-1")), - new SugarParameter("@TestId", 0) + new SugarParameter("@CreateTime", Convert.ToDateTime("2010-1-1")) }, t8.Key, t8.Value, diff --git a/SqlSugar/Abstract/Core/SqlBuilder/DMLBuilder/DeleteBuilder.cs b/SqlSugar/Abstract/Core/SqlBuilder/DMLBuilder/DeleteBuilder.cs index 33c44895e..35a57c371 100644 --- a/SqlSugar/Abstract/Core/SqlBuilder/DMLBuilder/DeleteBuilder.cs +++ b/SqlSugar/Abstract/Core/SqlBuilder/DMLBuilder/DeleteBuilder.cs @@ -58,7 +58,7 @@ namespace SqlSugar { get { - return "{0}=N'{1}'"; + return "[{0}]=N'{1}'"; } } diff --git a/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs b/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs index b69e80a6c..3b2fee9d9 100644 --- a/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs +++ b/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs @@ -63,7 +63,7 @@ namespace SqlSugar primaryKeyValues.Add(value); } var inValueString = primaryKeyValues.ToArray().ToJoinSqlInVals(); - Where(string.Format(DeleteBuilder.WhereInTemplate, primaryFields.Single(), inValueString)); + Where(string.Format(DeleteBuilder.WhereInTemplate,SqlBuilder.GetTranslationColumnName(primaryFields.Single()), inValueString)); } else { @@ -140,7 +140,7 @@ namespace SqlSugar string primaryField = null; primaryField = GetPrimaryKeys().FirstOrDefault(); Check.ArgumentNullException(primaryField, "Table " + tableName + " with no primarykey"); - Where(string.Format(DeleteBuilder.WhereInTemplate, primaryField, primaryKeyValues.ToJoinSqlInVals())); + Where(string.Format(DeleteBuilder.WhereInTemplate,SqlBuilder.GetTranslationColumnName(primaryField), primaryKeyValues.ToJoinSqlInVals())); return this; } diff --git a/SqlSugar/SqlSugarAccessory.cs b/SqlSugar/SqlSugarAccessory.cs index b97ecf32d..bd4dc69d9 100644 --- a/SqlSugar/SqlSugarAccessory.cs +++ b/SqlSugar/SqlSugarAccessory.cs @@ -64,6 +64,12 @@ namespace SqlSugar } private void InitMppingInfo(EntityInfo entityInfo) { + if (this.MappingTables == null) + this.MappingTables = new MappingTableList(); + if (this.MappingColumns == null) + this.MappingColumns = new MappingColumnList(); + if (this.IgnoreColumns == null) + this.IgnoreColumns = new IgnoreComumnList(); if (!this.MappingTables.Any(it => it.EntityName == entityInfo.EntityName)) { if (entityInfo.DbTableName != entityInfo.EntityName)