本文主要是介绍ABP框架—后台:引入Abp.Dapper(10),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、NuGet获取Abp.Dapper
项目类库Application和项目类库EntityFrameworkCore添加Abp.Dapper引用,如图:
二、创建实体Entity
项目类库Core创建实体,如图:
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中为实体定义数据库集
public virtual DbSet<Menu.Sys_Menu> Sys_Menu { set; get; }
四、EntityFrameworkModule添加依赖
typeof(AbpDapperModule)
DapperExtensions.DapperExtensions.SetMappingAssemblies(new List<Assembly> { typeof(VerifyServiceEntityFrameworkModule).GetAssembly()})
五、创建服务接口Application
调用默认的IDapperRepository
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_Menu> _Sys_MenuDapperRepository;public MenuTestAppService(IDapperRepository<Sys_Menu> 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框架—后台:引入Abp.Dapper(10)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!