您现在的位置是:网站首页> 编程资料编程资料

ABP引入Dapper框架的创建使用_实用技巧_

2023-05-24 344人已围观

简介 ABP引入Dapper框架的创建使用_实用技巧_

ABP使用Dapper框架已经有很成熟的第三方包,简单的几句代码就能完成

一. 首先准备好一个数据库建一个表

二.建一个实体表

 [Table("BasBloodLevel")] public class BasBloodLevel:Entity { 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 _basBloodLevelRepository; public BasBloodLevelAppService( IDapperRepository basBloodLevelRepository ) { _basBloodLevelRepository = basBloodLevelRepository; } public List GetBasAllMessage2() { var entity = _basBloodLevelRepository.Query("select * from BasBloodLevel").ToList(); return entity; } }

 调用以下证明我成功了

到这了就可以很简单的在ABP框架使用 Dapper 框架了,甚至可以做到 和EF无缝切换,这都得归功于Abp.Dapper这个包。那么如果要引入SqlSugar这个框架呢,下一篇我会写一篇模仿Abp.Dapper这个包的一些引入方法,更多关于ABP引入Dapper框架的资料请关注其它相关文章!

-六神源码网