mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
- 修复 CodeFirst + AsTable + 自动迁移,导致索性名重复的问题 #366;
This commit is contained in:
@ -4,14 +4,28 @@ using System.Text;
|
||||
|
||||
namespace FreeSql.DataAnnotations
|
||||
{
|
||||
/// <summary>
|
||||
/// 索引设置,如:[Index("{tablename}_idx_01", "name")]
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||
public class IndexAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 索引设置,如:[Index("{tablename}_idx_01", "name")]
|
||||
/// </summary>
|
||||
/// <param name="name">索引名<para></para>v1.7.0 增加占位符 {TableName} 表名区分索引名 (解决 AsTable 分表 CodeFirst 导致索引名重复的问题)</param>
|
||||
/// <param name="fields">索引字段,为属性名以逗号分隔,如:Create_time ASC, Title ASC</param>
|
||||
public IndexAttribute(string name, string fields)
|
||||
{
|
||||
this.Name = name;
|
||||
this.Fields = fields;
|
||||
}
|
||||
/// <summary>
|
||||
/// 索引设置,如:[Index("{tablename}_idx_01", "name", true)]
|
||||
/// </summary>
|
||||
/// <param name="name">索引名<para></para>v1.7.0 增加占位符 {TableName} 表名区分索引名 (解决 AsTable 分表 CodeFirst 导致索引名重复的问题)</param>
|
||||
/// <param name="fields">索引字段,为属性名以逗号分隔,如:Create_time ASC, Title ASC</param>
|
||||
/// <param name="isUnique">是否唯一</param>
|
||||
public IndexAttribute(string name, string fields, bool isUnique)
|
||||
{
|
||||
this.Name = name;
|
||||
@ -19,7 +33,8 @@ namespace FreeSql.DataAnnotations
|
||||
this.IsUnique = isUnique;
|
||||
}
|
||||
/// <summary>
|
||||
/// 索引名
|
||||
/// 索引名<para></para>
|
||||
/// v1.7.0 增加占位符 {TableName} 表名区分索引名 (解决 AsTable 分表 CodeFirst 导致索引名重复的问题)
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
|
@ -274,9 +274,30 @@
|
||||
<param name="exp"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:FreeSql.DataAnnotations.IndexAttribute">
|
||||
<summary>
|
||||
索引设置,如:[Index("{tablename}_idx_01", "name")]
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.DataAnnotations.IndexAttribute.#ctor(System.String,System.String)">
|
||||
<summary>
|
||||
索引设置,如:[Index("{tablename}_idx_01", "name")]
|
||||
</summary>
|
||||
<param name="name">索引名<para></para>v1.7.0 增加占位符 {TableName} 表名区分索引名 (解决 AsTable 分表 CodeFirst 导致索引名重复的问题)</param>
|
||||
<param name="fields">索引字段,为属性名以逗号分隔,如:Create_time ASC, Title ASC</param>
|
||||
</member>
|
||||
<member name="M:FreeSql.DataAnnotations.IndexAttribute.#ctor(System.String,System.String,System.Boolean)">
|
||||
<summary>
|
||||
索引设置,如:[Index("{tablename}_idx_01", "name", true)]
|
||||
</summary>
|
||||
<param name="name">索引名<para></para>v1.7.0 增加占位符 {TableName} 表名区分索引名 (解决 AsTable 分表 CodeFirst 导致索引名重复的问题)</param>
|
||||
<param name="fields">索引字段,为属性名以逗号分隔,如:Create_time ASC, Title ASC</param>
|
||||
<param name="isUnique">是否唯一</param>
|
||||
</member>
|
||||
<member name="P:FreeSql.DataAnnotations.IndexAttribute.Name">
|
||||
<summary>
|
||||
索引名
|
||||
索引名<para></para>
|
||||
v1.7.0 增加占位符 {TableName} 表名区分索引名 (解决 AsTable 分表 CodeFirst 导致索引名重复的问题)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.DataAnnotations.IndexAttribute.Fields">
|
||||
|
@ -9,6 +9,7 @@ using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Internal.CommonProvider
|
||||
@ -124,5 +125,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
|
||||
public virtual int ExecuteDDLStatements(string ddl) => _orm.Ado.ExecuteNonQuery(CommandType.Text, ddl);
|
||||
|
||||
public static string ReplaceIndexName(string indexName, string tbname) => string.IsNullOrEmpty(indexName) ? indexName : Regex.Replace(indexName, @"\{\s*TableName\s*\}", tbname, RegexOptions.IgnoreCase);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user