Introduction

Dapper is an object-relational mapper (ORM) for .NET. Abp.Dapper package simply integrates Dapper to ASP.NET Boilerplate. It works as secondary ORM provider with EF 6.x, EF Core or NHibernate.

Installation

Before you start, you need to install Abp.Dapper and one of EF Core, EF 6.x and NHibernate ORM nuget packages to project that you want to use it.

Module Registration

First you need to add DependsOn attribute for AbpDapperModule on your module where you register it.

[DependsOn(
typeof(AbpEntityFrameworkCoreModule),
typeof(AbpDapperModule)
)]
public class MyModule : AbpModule
{
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(typeof(SampleApplicationModule).GetAssembly());
}
}

Note that AbpDapperModule dependency should be added later than EF Core dependency.

Entity to Table Mapping

You can configure mappings. For example, Person class maps to Persons table in the following example:

public class PersonMapper : ClassMapper<Person>
{
public PersonMapper()
{
Table("Persons");
Map(x => x.Roles).Ignore();
AutoMap();
}
}

You should set the assemblies contains mapper classes. Excample:

[DependsOn(
typeof(AbpEntityFrameworkModule),
typeof(AbpDapperModule)
)]
public class MyModule : AbpModule
{
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(typeof(SampleApplicationModule).GetAssembly());
DapperExtensions.SetMappingAssemblies(new List<Assembly> { typeof(MyModule).GetAssembly() });
}
}

Usage

After registering AbpDapperModule, you can use Generic IDapperRepository interface (instead of standard IRepository) to inject dapper repositories.

public class SomeApplicationService : ITransientDependency
{
private readonly IDapperRepository<Person> _personDapperRepository;
private readonly IRepository<Person> _personRepository; public SomeApplicationService(
IRepository<Person> personRepository,
IDapperRepository<Person> personDapperRepository)
{
_personRepository = personRepository;
_personDapperRepository = personDapperRepository;
} public void DoSomeStuff()
{
var people = _personDapperRepository.Query("select * from Persons");
}
}

You can use both EF repositories and Dapper repositories at the same time, in the same transaction.

ABP框架系列之十六:(Dapper-Integration-Dapper集成)的更多相关文章

  1. ABP框架系列之四十六:(Setting-Management-设置管理)

    Introduction Every application need to store some settings and use these settings in somewhere in th ...

  2. ABP框架系列之三十六:(MVC-Views-MVC视图)

    Introduction ASP.NET Boilerplate is integrated to MVC Views via Abp.Web.Mvc nuget package. You can c ...

  3. ABP框架系列之五十四:(XSRF-CSRF-Protection-跨站请求伪造保护)

    Introduction "Cross-Site Request Forgery (CSRF) is a type of attack that occurs when a maliciou ...

  4. ABP框架系列之三十四:(Multi-Tenancy-多租户)

    What Is Multi Tenancy? "Software Multitenancy refers to a software architecture in which a sing ...

  5. ABP框架系列之三十八:(NHibernate-Integration-NHibernate-集成)

    ASP.NET Boilerplate can work with any O/RM framework. It has built-in integration with NHibernate. T ...

  6. ABP框架系列之三十九:(NLayer-Architecture-多层架构)

    Introduction Layering of an application's codebase is a widely accepted technique to help reduce com ...

  7. ABP框架系列之四十九:(Startup-Configuration-启动配置)

    ASP.NET Boilerplate provides an infrastructure and a model to configure it and modules on startup. A ...

  8. ABP框架系列之十五:(Caching-缓存)

    Introduction ASP.NET Boilerplate provides an abstraction for caching. It internally uses this cache ...

  9. ABP框架系列之三十二:(Logging-登录)

    Server Side(服务端) ASP.NET Boilerplate uses Castle Windsor's logging facility. It can work with differ ...

随机推荐

  1. Sql server 编写99乘法表

    Sql 组织编写语句 declare @one int,@tow int,@str varchar(100),@num intselect @one=1while(@one<=9)beginse ...

  2. 502 Bad Gateway

    状态码解释: 502 Bad Gateway:作为网关或者代理工作的服务器尝试执行请求时,从上游服务器接收到无效的响应. 502 原因分析: 将请求提交给网关如php-fpm执行,但是由于某些原因没有 ...

  3. day37协程与线程套接字通讯

    协程与线程套接字通讯基于多线程实现套接字服务端支持并发,服务端 from socket import * from threading import Thread def comunicate(con ...

  4. Java序列化机制原理

      Java序列化就是将一个对象转化为一个二进制表示的字节数组,通过保存或则转移这些二进制数组达到持久化的目的.要实现序列化,需要实现java.io.Serializable接口.反序列化是和序列化相 ...

  5. 6.HTML+CSS制作一双眼睛

    效果地址:https://codepen.io/flyingliao/pen/oOLodJ?editors=1100 其它动画效果地址:1.https://scrimba.com/c/cJ8NPpU2 ...

  6. boost安装缺少libboost_iostreams.so

    编译安装boost库: 1 ./bootstrap.sh 2 ./bjam 3 ./b2 install 但安装boosth后,发现缺少libboost_iostreams.so库,后发现boost库 ...

  7. leetcode739

    class Solution(object): def dailyTemperatures(self, T: 'List[int]') -> 'List[int]': S = list() n ...

  8. Echarts报错 Can't read property 'getWidth' of null

    统计图报错: 这里的报错与echarts无关,与zrender有关,zrender是echarts依赖的canvas绘图库 你不需要了解zrender,这个问题是你代码出了错 谨记::代码的错

  9. 【Noip模拟 20160929】树林

    题目描述 现在有一片树林,小B很想知道,最少需要多少步能围绕树林走一圈,最后回到起点.他能上下左右走,也能走对角线格子. 土地被分成RR行CC列1≤R≤50,1≤C≤501≤R≤50,1≤C≤50,下 ...

  10. MySQL慢查询日志相关的配置和使用。

    MySQL慢查询日志提供了超过指定时间阈值的查询信息,为性能优化提供了主要的参考依据,是一个非常实用的功能,MySQL慢查询日志的开启和配置非常简单,可以指定记录的文件(或者表),超过的时间阈值等就可 ...