Browse Source

Synchronization code

pull/25/head
sunkaixuan 2 years ago
parent
commit
cf4459caae
  1. 8
      Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs
  2. 15
      Src/Asp.NetCore2/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs

8
Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -268,6 +268,7 @@ namespace SqlSugar
{
item.IndexName = (this.Context.CurrentConnectionConfig.IndexSuffix+ item.IndexName);
}
var include = "";
if (item.IndexName != null)
{
var database = "{db}";
@ -280,6 +281,11 @@ namespace SqlSugar
{
item.IndexName = item.IndexName.Replace(table, entityInfo.DbTableName);
}
if (item.IndexName.ToLower().Contains("{include:"))
{
include=Regex.Match( item.IndexName,@"\{include\:.+$").Value;
item.IndexName = item.IndexName.Replace(include, "");
}
}
if (!this.Context.DbMaintenance.IsAnyIndex(item.IndexName))
{
@ -296,7 +302,7 @@ namespace SqlSugar
return new KeyValuePair<string, OrderByType>(dbColumn.DbColumnName, it.Value);
})
.Select(it => querybulder.GetTranslationColumnName(it.Key) + " " + it.Value).ToArray();
this.Context.DbMaintenance.CreateIndex(entityInfo.DbTableName, fileds, item.IndexName, item.IsUnique);
this.Context.DbMaintenance.CreateIndex(entityInfo.DbTableName, fileds, item.IndexName+ include, item.IsUnique);
}
}
}

15
Src/Asp.NetCore2/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace SqlSugar
{
@ -467,7 +468,19 @@ namespace SqlSugar
}
public virtual bool CreateIndex(string tableName, string[] columnNames, string IndexName, bool isUnique = false)
{
string sql = string.Format("CREATE {3} INDEX {2} ON {0}({1})", tableName, string.Join(",", columnNames), IndexName, isUnique ? "UNIQUE" : "");
var include = "";
if (IndexName.ToLower().Contains("{include:"))
{
include = Regex.Match(IndexName, @"\{include\:.+$").Value;
IndexName = IndexName.Replace(include, "");
if (include == null)
{
throw new Exception("include format error");
}
include = include.Replace("{include:", "").Replace("}", "");
include = $"include({include})";
}
string sql = string.Format("CREATE {3} INDEX {2} ON {0}({1})"+ include, tableName, string.Join(",", columnNames), IndexName, isUnique ? "UNIQUE" : "");
this.Context.Ado.ExecuteCommand(sql);
return true;
}

Loading…
Cancel
Save