在Core项目中新建Task类,通过标签定义表名和字段
<官方说明:默认情况下它包含 Id 属性为 int。我们可以使用通用版本 Entity 来选择不同的 PK 类型。
IHasCreationTime 是一个简单的接口,只定义了 CreationTime 属性(最好为 CreationTime 使用标准名称)。
任务实体定义了一个必需的标题和一个可选的描述。
TaskState 是一个简单的枚举,用于定义任务的状态。
Clock.Now 默认返回 DateTime.Now。但它提供了一个抽象,因此我们可以在需要时轻松切换到功能中的 DateTime.UtcNow。在使用 ABP 框架时,请始终使用 Clock.Now 而不是 DateTime.Now。
我想将任务实体存储到数据库中的 AppTasks 表中。>
内容如下,来自官方文档
using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using Abp.Timing;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abpsimple.Tasks
{
[Table("AppTasks")]
public class Task : Entity, IHasCreationTime
{
public const int MaxTitleLength = 256;
public const int MaxDescriptionLength = 64 * 1024; //64KB
[Required]
[StringLength(MaxTitleLength)]
public string Title { get; set; }
[StringLength(MaxDescriptionLength)]
public string Description { get; set; }
public DateTime CreationTime { get; set; }
public TaskState State { get; set; }
public Task()
{
CreationTime = Clock.Now;
State = TaskState.Open;
}
public Task(string title, string description = null)
: this()
{
Title = title;
Description = description;
}
}
public enum TaskState : byte
{
Open = 0,
Completed = 1
}
}
通过PM选择默认程序EntityFrameworkCore并执行命令Add-Migration “一个名称”,就会生成一个"当前日期-你的名称"的一个增量文件,记录了新增的表结构。该文件在EntityFrameworkCore项目中的Migration文件夹里。
通过PM选择默认程序EntityFrameworkCore并执行命令Update-Database,可以将Migration里的配置都更新到数据库。
程序包控制器管理台(以上简称PM)