Search Results for

    Show / Hide Table of Contents

    Class ColumnAttribute

    Inheritance
    System.Object
    System.Attribute
    ColumnAttribute
    Inherited Members
    System.Attribute.Equals(System.Object)
    System.Attribute.GetCustomAttribute(System.Reflection.Assembly, System.Type)
    System.Attribute.GetCustomAttribute(System.Reflection.Assembly, System.Type, System.Boolean)
    System.Attribute.GetCustomAttribute(System.Reflection.MemberInfo, System.Type)
    System.Attribute.GetCustomAttribute(System.Reflection.MemberInfo, System.Type, System.Boolean)
    System.Attribute.GetCustomAttribute(System.Reflection.Module, System.Type)
    System.Attribute.GetCustomAttribute(System.Reflection.Module, System.Type, System.Boolean)
    System.Attribute.GetCustomAttribute(System.Reflection.ParameterInfo, System.Type)
    System.Attribute.GetCustomAttribute(System.Reflection.ParameterInfo, System.Type, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.Assembly)
    System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Type)
    System.Attribute.GetCustomAttributes(System.Reflection.Assembly, System.Type, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo)
    System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Type)
    System.Attribute.GetCustomAttributes(System.Reflection.MemberInfo, System.Type, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.Module)
    System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Type)
    System.Attribute.GetCustomAttributes(System.Reflection.Module, System.Type, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo)
    System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Boolean)
    System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Type)
    System.Attribute.GetCustomAttributes(System.Reflection.ParameterInfo, System.Type, System.Boolean)
    System.Attribute.GetHashCode()
    System.Attribute.IsDefaultAttribute()
    System.Attribute.IsDefined(System.Reflection.Assembly, System.Type)
    System.Attribute.IsDefined(System.Reflection.Assembly, System.Type, System.Boolean)
    System.Attribute.IsDefined(System.Reflection.MemberInfo, System.Type)
    System.Attribute.IsDefined(System.Reflection.MemberInfo, System.Type, System.Boolean)
    System.Attribute.IsDefined(System.Reflection.Module, System.Type)
    System.Attribute.IsDefined(System.Reflection.Module, System.Type, System.Boolean)
    System.Attribute.IsDefined(System.Reflection.ParameterInfo, System.Type)
    System.Attribute.IsDefined(System.Reflection.ParameterInfo, System.Type, System.Boolean)
    System.Attribute.Match(System.Object)
    System.Attribute.TypeId
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: FreeSql.DataAnnotations
    Assembly: FreeSql.dll
    Syntax
    [AttributeUsage(AttributeTargets.Property)]
    public class ColumnAttribute : Attribute

    Properties

    | Improve this Doc View Source

    CanInsert

    该字段是否可以插入,默认值true,指定为false插入时该字段会被忽略

    Declaration
    public bool CanInsert { get; set; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    CanUpdate

    该字段是否可以更新,默认值true,指定为false更新时该字段会被忽略

    Declaration
    public bool CanUpdate { get; set; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    DbType

    数据库类型,如: varchar(255)

    字符串长度,可使用特性 [MaxLength(255)]

    Declaration
    public string DbType { get; set; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    InsertValueSql

    执行 Insert 方法时使用此值

    注意:如果是 getdate() 这种请可考虑使用 ServerTime,因为它对数据库间作了适配

    Declaration
    public string InsertValueSql { get; set; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    IsIdentity

    自增标识

    Declaration
    public bool IsIdentity { get; set; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    IsIgnore

    忽略此列,不迁移、不插入

    Declaration
    public bool IsIgnore { get; set; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    IsNullable

    是否可DBNull

    Declaration
    public bool IsNullable { get; set; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    IsPrimary

    主键

    Declaration
    public bool IsPrimary { get; set; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    IsVersion

    设置行锁(乐观锁)版本号,每次更新累加版本号,若更新整个实体时会附带当前的版本号判断(修改失败时抛出异常)

    Declaration
    public bool IsVersion { get; set; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    MapType

    类型映射,除了可做基本的类型映射外,特别介绍的功能:

    1、将 enum 属性映射成 typeof(string)

    2、将 对象 属性映射成 typeof(string),请安装扩展包 FreeSql.Extensions.JsonMap

    Declaration
    public Type MapType { get; set; }
    Property Value
    Type Description
    System.Type
    | Improve this Doc View Source

    Name

    数据库列名

    Declaration
    public string Name { get; set; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    OldName

    指定数据库旧的列名,修改实体属性命名时,同时设置此参数为修改之前的值,CodeFirst才可以正确修改数据库字段;否则将视为【新增字段】

    Declaration
    public string OldName { get; set; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    Position

    创建表时字段的位置(场景:实体继承后设置字段顺序),规则如下:

    >0时排前面,1,2,3...

    =0时排中间(默认)

    <0时排后面,...-3,-2,-1

    Declaration
    public short Position { get; set; }
    Property Value
    Type Description
    System.Int16
    | Improve this Doc View Source

    Precision

    decimal/numeric 类型的长度

    Declaration
    public int Precision { get; set; }
    Property Value
    Type Description
    System.Int32
    | Improve this Doc View Source

    RereadSql

    重读功能

    比如:[Column(RereadSql = "{0}.STAsText()")]

    查询:SELECT a.[id], a.[geo].STAsText() FROM [table] a

    Declaration
    public string RereadSql { get; set; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    RewriteSql

    重写功能

    比如:[Column(RewriteSql = "geography::STGeomFromText({0},4236)")]

    插入:INSERT INTO table VALUES(geography::STGeomFromText('...',4236))

    提示:更新也生效

    Declaration
    public string RewriteSql { get; set; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    Scale

    decimal/numeric 类型的小数位长度

    Declaration
    public int Scale { get; set; }
    Property Value
    Type Description
    System.Int32
    | Improve this Doc View Source

    ServerTime

    标记属性为数据库服务器时间(utc/local),在插入的时候使用类似 getdate() 执行

    Declaration
    public DateTimeKind ServerTime { get; set; }
    Property Value
    Type Description
    System.DateTimeKind
    | Improve this Doc View Source

    StringLength

    设置长度,针对 string/byte[] 类型避免 DbType 的繁琐设置

    提示:也可以使用 [MaxLength(100)]

    ---

    StringLength = 100 时,对应 DbType:

    MySql -> varchar(100)

    SqlServer -> nvarchar(100)

    PostgreSQL -> varchar(100)

    Oracle -> nvarchar2(100)

    Sqlite -> nvarchar(100)

    ---

    StringLength < 0 时,对应 DbType:

    MySql -> text (StringLength = -2 时,对应 longtext)

    SqlServer -> nvarchar(max)

    PostgreSQL -> text

    Oracle -> nclob

    Sqlite -> text

    v1.6.0+ byte[] 支持设置 StringLength

    Declaration
    public int StringLength { get; set; }
    Property Value
    Type Description
    System.Int32
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX