插入表(一)

使用的类

Snowflake

    [SugarTable("Snowflake")]
    public class Snowflake
    {
        [SugarColumn(IsPrimaryKey = true)]//数据库是自增才配自增 
        public long Id { get; set; }
        public int? SchoolId { get; set; }
        [SugarColumn(ColumnName = "StudentName")]//数据库与实体不一样设置列名 
        public string? Name { get; set; }
    }

Student

[SugarTable("dbstudent")]//当和数据库名称不一样可以设置表别名 指定表明
    public class Student
    {
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//数据库是自增才配自增 
        public int Id { get; set; }

        [SugarColumn(ColumnName = "SchoolId", IsNullable = true)]
        public int? SchoolId { get; set; }

        [SugarColumn(ColumnName = "StudentName", IsNullable = true)]//数据库与实体不一样设置列名 
        public string? Name { get; set; }

        //[SugarColumn(IsOnlyIgnoreInsert = true)]//设置后插入会取数据库默认值
        [SugarColumn(ColumnName = "CreateTime", IsNullable = true)]
        public DateTime? CreateTime { get; set; }
    }

UserInfo

    [SugarTable("UserInfo")]//当和数据库名称不一样可以设置表别名 指定表明
    public class UserInfo
    {

    [SugarColumn(IsPrimaryKey = true)]
    public Guid uId { get; set; }    

    [SugarColumn(ColumnName = "Name", IsNullable = true)]
    public string? Name { get; set; }

    [SugarColumn(ColumnName = "CreateTime", IsNullable = true)]
    public DateTime? CreateTime { get; set; }


    /// <summary>
    /// 租户Id
    /// </summary>
    public int OrgId { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public string? Connection { get; set; }
}

UnitInsertMethod

    public class UnitInsertMethod
    {
        public int Id { get; set; }
        public string Name { get; set; }

        public DateTime Time { get; set; }
        public string UserId { get; set; }

        public void Create() 
        {
            this.Time= DateTime.Now;
            this.UserId = "1";
        }
        public void Modify(string a) 
        {
            this.Time= DateTime.Now;
            this.UserId = a;
        }
    }
此条目发表在SQL Sugar分类目录。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注