diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs index 3c853a7d5..f80ffa02b 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs @@ -10,9 +10,19 @@ namespace OrmTest { public static void CodeFirst() { + Db.CodeFirst.InitTables(); if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false)) Db.DbMaintenance.DropTable("UnitCodeTest1"); Db.CodeFirst.InitTables(); + Db.CodeFirst.InitTables(); + } + + public class UnitCodeFirstpks2 + { + [SqlSugar.SugarColumn(IsPrimaryKey =true)] + public string id { get; set; } + [SqlSugar.SugarColumn(IsPrimaryKey = true)] + public string id2 { get; set; } } public class UnitCodeTest1 { diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs index 8f9bda534..233e19033 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs @@ -179,7 +179,8 @@ namespace SqlSugar { tableName = this.SqlBuilder.GetTranslationTableName(tableName); var columnName = string.Join(",", columnNames); - string sql = string.Format(this.AddPrimaryKeySql, tableName, string.Format("PK_{0}_{1}", this.SqlBuilder.GetNoTranslationColumnName(columnNames.First()), this.SqlBuilder.GetNoTranslationColumnName(columnNames.First())), columnName); + var pkName = string.Format("PK_{0}_{1}", this.SqlBuilder.GetNoTranslationColumnName(tableName), columnName.Replace(",","_")); + string sql = string.Format(this.AddPrimaryKeySql, tableName,pkName, columnName); this.Context.Ado.ExecuteCommand(sql); return true; }