本篇内容主要讲解“ABP引入Dapper框架怎么创建使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“ABP引入Dapper框架怎么创建使用”吧!
一. 首先准备好一个数据库建一个表

二.建一个实体表
[Table("BasBloodLevel")]
public class BasBloodLevel:Entity<int>
{
public string Code { get; set; }
}
三.然后再ABP框架的EF层安装 Abp.Dapper包
Abp.Dapper包
并且在EF层的 xxxEntityFrameworkModule添加以下代码


到此引用 Dapper框架就完成了,接下来就是使用了
使用
首先DbContext引入对应的DbSet

最后在应用层直接使用
使用 IDapperRepository的仓储就能使用Dapper的ORM框架了
public class BasBloodLevelAppService : IApplicationService
{
private readonly IDapperRepository<BasBloodLevel, int> _basBloodLevelRepository;
public BasBloodLevelAppService(
IDapperRepository<BasBloodLevel, int> basBloodLevelRepository
)
{
_basBloodLevelRepository = basBloodLevelRepository;
}
public List<BasBloodLevel> GetBasAllMessage2()
{
var entity = _basBloodLevelRepository.Query("select * from BasBloodLevel").ToList();
return entity;
}
}
调用以下证明我成功了

到此,相信大家对“ABP引入Dapper框架怎么创建使用”有了更深的了解,不妨来实际操作一番吧!这里是天达云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!