FreeSql 定义实体类实例

原创 freeguy  2023-03-05 21:20:09  阅读 2320 次 评论 0 条

using System;

using FreeSql.DataAnnotations;

 

namespace ConsoleForTestFreeSql

{

    //更多的解释,大家可以查看代码转到定义去查看

 

    //Name可以指定对应数据库哪张表(如果表名和类名相同,无需指定)

    [Table(Name = "TableName")]

    public class ClassInfo

    {

        //IsIdentity:是否自增标识列

        [Column(IsIdentity = true)]

        public int IdentityId { get; set; }

 

        //IsPrimary:是否主键

        //Name:对应数据库表列名(属性名和数据库字段名相同时无需指定)

        //如果列是guid类型,插入时会自动创建主键id,无需手动赋值(并且是支持分布式的)

        [Column(IsPrimary = true, Name = "Id")]

        public Guid Id { get; set; }

 

        //DbType:对应的数据库类型:如DbType = "nvarchar(50)"

        //IsNullable:是否可以为空

        [Column(DbType = "nvarchar(50)", IsNullable = false)]

        public string ClassName { get; set; }

 

        //StringLength:在指定数据库类型时,如果是string类型,除了自己指定,这里也可以指定最大长度

        [Column(StringLength = 300)]

        public string Des { get; set; }

 

        //IsIgnore:是否忽略列,不新增,不迁移

        [Column(IsIgnore = true)]

        public string Remark { get; set; }

 

        //IsVersion:版本号(乐观锁),修改时会使用到,一个表最多只允许一列版本号

        [Column(IsVersion = true)]

        public decimal Money { get; set; }

 

        //CanUpdate:false是修改时不修改此列

        //ServerTime:对应数据库服务器时间(插入时使用,是个枚举)

        [Column(CanUpdate = false, ServerTime = DateTimeKind.Local, IsNullable = false)]

        public DateTime CreateDate { get; set; }

 

        //CanInsert:false时新增时不新增此列

        [Column(CanInsert = false, ServerTime = DateTimeKind.Local)]

        public DateTime? LastUpdateDate { get; set; }

    }

}


本文地址:http://freedeman.top/?id=20
版权声明:本文为原创文章,版权归 freeguy 所有,欢迎分享本文,转载请保留出处!

评论已关闭!