Browse Source

Update AddPrimaryKeys

pull/2/head
skx 4 years ago
parent
commit
f944d339e9
  1. 10
      Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs
  2. 3
      Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs

10
Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs

@ -10,9 +10,19 @@ namespace OrmTest
{
public static void CodeFirst()
{
Db.CodeFirst.InitTables<UnitCodeFirstpks2>();
if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false))
Db.DbMaintenance.DropTable("UnitCodeTest1");
Db.CodeFirst.InitTables<UnitCodeTest1>();
Db.CodeFirst.InitTables<UnitCodeFirstpks2>();
}
public class UnitCodeFirstpks2
{
[SqlSugar.SugarColumn(IsPrimaryKey =true)]
public string id { get; set; }
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
public string id2 { get; set; }
}
public class UnitCodeTest1
{

3
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;
}

Loading…
Cancel
Save