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;
        }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM