From 70163e841e98f6feb5f5734ff93f53ea5d82a80b Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Wed, 13 Apr 2022 23:38:12 +0800 Subject: [PATCH] Update unit test --- Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs | 11 ++++++++++- .../Abstract/DbMaintenanceProvider/Methods.cs | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs index 6e574e2f1..5fdfe514a 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs @@ -48,8 +48,17 @@ namespace OrmTest db.CodeFirst.InitTables(); db.Insertable(new UnitGe() { geometry1 = "POINT (20 180)" }).ExecuteCommand(); var gelist=db.Queryable().Select(it=>new { geometry1 = it.geometry1.ToString()}).ToList(); + if (Db.DbMaintenance.IsAnyTable("User", false)) + Db.DbMaintenance.DropTable("User"); + db.CodeFirst.InitTables(); + } + public class User + { + [SugarColumn(IndexGroupNameList =new string[] { "index"})] + public int key { get; set; } + [SugarColumn(UniqueGroupNameList = new string[] { "index" })] + public int key2 { get; set; } } - public class UnitGe { [SugarColumn(ColumnDataType = "geometry")] diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs index 12bf743fa..81b23468b 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs @@ -315,13 +315,17 @@ namespace SqlSugar } public virtual bool CreateIndex(string tableName, string[] columnNames, bool isUnique=false) { - string sql = string.Format(CreateIndexSql,tableName,string.Join(",",columnNames), string.Join("_", columnNames) + this.Context.CurrentConnectionConfig.IndexSuffix, isUnique ? "UNIQUE" : ""); + string sql = string.Format(CreateIndexSql,this.SqlBuilder.GetTranslationTableName(tableName),string.Join(",",columnNames.Select(it=>this.SqlBuilder.GetTranslationColumnName(it))), string.Join("_", columnNames) + this.Context.CurrentConnectionConfig.IndexSuffix, isUnique ? "UNIQUE" : ""); + sql = sql.Replace("_" + this.SqlBuilder.SqlTranslationLeft, "_"); + sql = sql.Replace( this.SqlBuilder.SqlTranslationRight+"_", "_"); this.Context.Ado.ExecuteCommand(sql); return true; } public virtual bool CreateUniqueIndex(string tableName, string[] columnNames) { - string sql = string.Format(CreateIndexSql, tableName, string.Join(",", columnNames), string.Join("_", columnNames) + this.Context.CurrentConnectionConfig.IndexSuffix + "_Unique","UNIQUE" ); + string sql = string.Format(CreateIndexSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",", columnNames.Select(it => this.SqlBuilder.GetTranslationColumnName(it))), string.Join("_", columnNames) + this.Context.CurrentConnectionConfig.IndexSuffix + "_Unique","UNIQUE" ); + sql = sql.Replace("_" + this.SqlBuilder.SqlTranslationLeft, "_"); + sql = sql.Replace(this.SqlBuilder.SqlTranslationRight + "_", "_"); this.Context.Ado.ExecuteCommand(sql); return true; }