ABP框架—后台:引入Abp.Dapper(10)

一、NuGet获取Abp.Dapper

项目类库Application和项目类库EntityFrameworkCore添加Abp.Dapper引用,如图:

ABP框架—后台:引入Abp.Dapper(10)_第1张图片


二、创建实体Entity


项目类库Core创建实体,如图:

ABP框架—后台:引入Abp.Dapper(10)_第2张图片

 

using Abp.Domain.Entities;

namespace PD.Menu
{
    public class Sys_Menu : Entity  
    {
        public virtual string Path { get; set; }
        public virtual string Name { get; set; }
        public virtual string Permission { get; set; }
        public virtual string Meta { get; set; }
        public virtual string Title { get; set; }
        public virtual string Icon { get; set; }
        public virtual string Component { get; set; }
        public virtual int FatherId { get; set; }
        public virtual int LevelType { get; set; }
        public virtual int StatusType { get; set; }
    }
}

三、DbContext中为实体定义数据库集

ABP框架—后台:引入Abp.Dapper(10)_第3张图片

public virtual DbSet Sys_Menu { set; get; }


四、EntityFrameworkModule添加依赖

ABP框架—后台:引入Abp.Dapper(10)_第4张图片

typeof(AbpDapperModule)
DapperExtensions.DapperExtensions.SetMappingAssemblies(new List { typeof(VerifyServiceEntityFrameworkModule).GetAssembly()})


五、创建服务接口Application


调用默认的IDapperRepository

ABP框架—后台:引入Abp.Dapper(10)_第5张图片

using Abp.Dapper.Repositories;
using System;
using System.Collections.Generic;
using System.Text;

namespace PD.Menu
{
    public class MenuTestAppService : PDAppServiceBase, IMenuTestAppService
    {
        private readonly IDapperRepository _Sys_MenuDapperRepository;
        public MenuTestAppService(IDapperRepository sys_MenuDapperRepository)
        {
            _Sys_MenuDapperRepository = sys_MenuDapperRepository;
        }

        public void Get()
        {
            var aa = _Sys_MenuDapperRepository.GetAll();
            var bb = _Sys_MenuDapperRepository.Query("select * from Sys_Menu");
        }
    }
}


说明:ABP官方说明https://aspnetboilerplate.com/Pages/Documents/Dapper-Integration

 

 

你可能感兴趣的:(ABP框架学习日记,ASP.NET)