增加数据基础表定义。比SugarTableBase更加简洁。
This commit is contained in:
parent
ff91c94af2
commit
aad7cb83f2
49
Falcon.SugarApi/DatabaseDefinitions/SugarBasicTable.cs
Normal file
49
Falcon.SugarApi/DatabaseDefinitions/SugarBasicTable.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Falcon.SugarApi.DatabaseDefinitions
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础表,定义表基础数据结构和构造方法
|
||||
/// </summary>
|
||||
public abstract class SugarBasicTable
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
[SugarColumn(IsOnlyIgnoreUpdate = true, IsNullable = true, ColumnDescription = "创建时间")]
|
||||
public DateTime? CreateTime { get; set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 记录状态
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "记录状态。有效 无效")]
|
||||
public string Status { get; set; } = "有效";
|
||||
|
||||
/// <summary>
|
||||
/// 将数据设置为新数据。
|
||||
/// <para>主要更新Id、创建时间和记录状态</para>
|
||||
/// </summary>
|
||||
/// <returns>本条数据</returns>
|
||||
public virtual SugarBasicTable SetNew() {
|
||||
this.Id = Guid.NewGuid();
|
||||
this.CreateTime = DateTime.Now;
|
||||
this.Status = "有效";
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置本条记录有效状态
|
||||
/// </summary>
|
||||
/// <param name="enable">有效还是无效,默认有效</param>
|
||||
/// <returns>本条数据</returns>
|
||||
public virtual SugarBasicTable SetEnable(bool enable = true) {
|
||||
this.Status = enable ? "有效" : "无效";
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user