Class ColumnAttribute
Inheritance
Inherited Members
Namespace: FreeSql.DataAnnotations
Assembly: FreeSql.dll
Syntax
[AttributeUsage(AttributeTargets.Property)]
public class ColumnAttribute : Attribute
Properties
| Improve this Doc View SourceCanInsert
该字段是否可以插入,默认值true,指定为false插入时该字段会被忽略
Declaration
public bool CanInsert { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
CanUpdate
该字段是否可以更新,默认值true,指定为false更新时该字段会被忽略
Declaration
public bool CanUpdate { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
DbType
数据库类型,如: varchar(255)
字符串长度,可使用特性 [MaxLength(255)]
Declaration
public string DbType { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
InsertValueSql
执行 Insert 方法时使用此值
注意:如果是 getdate() 这种请可考虑使用 ServerTime,因为它对数据库间作了适配
Declaration
public string InsertValueSql { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
IsIdentity
自增标识
Declaration
public bool IsIdentity { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsIgnore
忽略此列,不迁移、不插入
Declaration
public bool IsIgnore { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsNullable
是否可DBNull
Declaration
public bool IsNullable { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsPrimary
主键
Declaration
public bool IsPrimary { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsVersion
设置行锁(乐观锁)版本号,每次更新累加版本号,若更新整个实体时会附带当前的版本号判断(修改失败时抛出异常)
Declaration
public bool IsVersion { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
MapType
类型映射,除了可做基本的类型映射外,特别介绍的功能:
1、将 enum 属性映射成 typeof(string)
2、将 对象 属性映射成 typeof(string),请安装扩展包 FreeSql.Extensions.JsonMap
Declaration
public Type MapType { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Type |
Name
数据库列名
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
OldName
指定数据库旧的列名,修改实体属性命名时,同时设置此参数为修改之前的值,CodeFirst才可以正确修改数据库字段;否则将视为【新增字段】
Declaration
public string OldName { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
Position
创建表时字段的位置(场景:实体继承后设置字段顺序),规则如下:
>0时排前面,1,2,3...
=0时排中间(默认)
<0时排后面,...-3,-2,-1
Declaration
public short Position { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int16 |
Precision
decimal/numeric 类型的长度
Declaration
public int Precision { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
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 |
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 |
Scale
decimal/numeric 类型的小数位长度
Declaration
public int Scale { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
ServerTime
标记属性为数据库服务器时间(utc/local),在插入的时候使用类似 getdate() 执行
Declaration
public DateTimeKind ServerTime { get; set; }
Property Value
| Type | Description |
|---|---|
| System.DateTimeKind |
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 |