diff --git a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index 12087f81a..471e574a2 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -234,10 +234,18 @@ namespace SqlSugar { item.IndexName = (this.Context.CurrentConnectionConfig.IndexSuffix+ item.IndexName); } - var database = "{db}"; - if (item.IndexName!=null&&item.IndexName.Contains(database)) + if (item.IndexName != null) { - item.IndexName = item.IndexName.Replace(database, this.Context.Ado.Connection.Database); + var database = "{db}"; + if (item.IndexName.Contains(database)) + { + item.IndexName = item.IndexName.Replace(database, this.Context.Ado.Connection.Database); + } + var table = "{table}"; + if (item.IndexName.Contains(table)) + { + item.IndexName = item.IndexName.Replace(table, entityInfo.DbTableName); + } } if (!this.Context.DbMaintenance.IsAnyIndex(item.IndexName)) { diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index 12087f81a..471e574a2 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -234,10 +234,18 @@ namespace SqlSugar { item.IndexName = (this.Context.CurrentConnectionConfig.IndexSuffix+ item.IndexName); } - var database = "{db}"; - if (item.IndexName!=null&&item.IndexName.Contains(database)) + if (item.IndexName != null) { - item.IndexName = item.IndexName.Replace(database, this.Context.Ado.Connection.Database); + var database = "{db}"; + if (item.IndexName.Contains(database)) + { + item.IndexName = item.IndexName.Replace(database, this.Context.Ado.Connection.Database); + } + var table = "{table}"; + if (item.IndexName.Contains(table)) + { + item.IndexName = item.IndexName.Replace(table, entityInfo.DbTableName); + } } if (!this.Context.DbMaintenance.IsAnyIndex(item.IndexName)) {