zoukankan      html  css  js  c++  java
  • 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;
            }
        }
    }
  • 相关阅读:
    hibernate各种状态
    Persistence createEntityManagerFactory方法使用
    JS数组学习笔记
    ES6笔记之参数默认值(译)
    JS是按值传递还是按引用传递?
    linux awk命令详解
    Linux Shell笔记之sed
    类似微信红包随机分配js方法
    ionic tabs隐藏完美解决
    mustache 获取json数据内数组对象指定元素的方法
  • 原文地址:https://www.cnblogs.com/dacaba/p/9910726.html
Copyright © 2011-2022 走看看