ABP学习笔记-维护数据库

在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)
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值