FreeSql/FreeSql/DataAnnotations/IndexAttribute.cs

63 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
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;
this.Fields = fields;
this.IsUnique = isUnique;
}
/// <summary>
/// 索引名<para></para>
/// v1.7.0 增加占位符 {TableName} 表名区分索引名 (解决 AsTable 分表 CodeFirst 导致索引名重复的问题)
/// </summary>
public string Name { get; set; }
/// <summary>
/// 索引字段为属性名以逗号分隔Create_time ASC, Title ASC
/// </summary>
public string Fields { get; set; }
internal bool? _IsUnique;
/// <summary>
/// 是否唯一
/// </summary>
public bool IsUnique { get => _IsUnique ?? false; set => _IsUnique = value; }
/// <summary>
/// 索引类型<para></para>
/// 暂时只有 FreeSql.Provider.PostgreSQL 有效
/// </summary>
public IndexMethod IndexMethod { get; set; }
}
/// <summary>
/// 暂时只有 FreeSql.Provider.PostgreSQL 有效
/// </summary>
public enum IndexMethod { B_Tree, Hash, GiST, GIN, SP_GiST, BRIN }
}