ABP.Net Core使用教程(二)添加一个实体

1,在领域层(Core)添加Person实体

namespace AbpDemo.Persons
{
    public class Person : FullAuditedEntity
    {
        public string Name { get; set; }
        public int Sex { get; set; }
    }
}

2,在基础层(EntityFrameworkCore)的类AbpDemoDbContext添加数据集Persons

namespace AbpDemo.EntityFrameworkCore
{
    public class AbpDemoDbContext : AbpZeroDbContext<Tenant, Role, User, AbpDemoDbContext>
    {
        /* Define a DbSet for each entity of the application */

        public AbpDemoDbContext(DbContextOptions<AbpDemoDbContext> options)
            : base(options)
        {
        }

        public DbSet<Person> Persons { get; set; }

        //创建模型
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Person>().ToTable("Person"); //设置表名

            base.OnModelCreating(modelBuilder);
        }
    }
}

3,数据迁移,在数据库产生表Person

说到数据迁移,我用不好,为了防止删除生产环境的数据库,我完全启用数据迁移,手动编写所有的表脚本和种子数据脚本,在生产环境执行

4,利用代码生成器产生增删改查的接口

先搜索abp安装如下插件 :ABP Code Power Tools by 52abp.com

安装好之后右键实体类,产生代码即可

会有一些报错,修复一些就好

如果提示这个类不存在:PagedSortedAndFilteredInputDto

代码如下:

namespace AbpDemo.Dtos
{
    public class PagedSortedAndFilteredInputDto : PagedAndSortedInputDto
    {
        public string FilterText { get; set; }

    }
}
namespace AbpDemo.Dtos
{
    public class PagedAndSortedInputDto : PagedInputDto, ISortedResultRequest
    {
        public string Sorting { get; set; }


        public PagedAndSortedInputDto()
        {
            MaxResultCount = AppLtmConsts.DefaultPageSize;
        }
    }
}

 

posted @ 2018-11-05 18:35  包子大叔  阅读(1997)  评论(1编辑  收藏  举报