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. Keras处理已保存模型中的自定义层(或其他自定义对象)

    如果要加载的模型包含自定义层或其他自定义类或函数,则可以通过 custom_objects 参数将它们传递给加载机制: from keras.models import load_model # 假设 ...

  2. linux服务之apache篇(一)

    1.apache介绍:使用率最高的网站服务器: URL:统一资源定位符: 端口:http:80   https:443 2.apache三种工作模式: prefork:一个线程处理一个请求(占用内存多 ...

  3. 第一课了解SQL

    1.1 数据库基础 其实一直在使用这数据库,当你在邮箱中查询名字时,当在网站上进行搜索,在自动取款机上使用ATM卡,这些操作都是在使用数据库 1.1.1 数据库   数据库:保存有组织的数据的容器(通 ...

  4. 性能测试day06_需求设计的学习(性能重中之重,思维方向永远重于工具)

    今天接着来学习下性能知识,本来是应该先学习一下LR的用法的,不过听完云层大大的课之后,我感觉工具没有这一篇来的重要,我们知道性能有三大步骤:负载->监控->调优,但是在这个之前我们首先要搞 ...

  5. android 开发 View _5_ Paint详解

    转载:http://blog.csdn.net/abcdef314159 //Paint的setStyle,Style共有3种 setStyle(Style style) Paint.Style.FI ...

  6. html: 仿制soundmanager2右上角面板

    仿制 http://schillmania.com/projects/soundmanager2/#volume 右上角面板 <style type="text/css"&g ...

  7. (2) linux文件系统简介

    bin -- 存放可执行的命令程序 sbin -- 系统管理相关的命令程序 boot -- 存放启动相关的内容 dev -- 存放设备和硬件 etc -- 存放程序,系统的配置文件 home -- 存 ...

  8. Django之如何预防csrf功能的方式 form提交与ajax提交

    1. 什么是csrf认证: 主要是防止别人恶意登录你的账户信息用的: 2. csrf认证在django的实现方式: 分为两种, 一种是from表单提交的方式,另一种是ajax提交实现方式 前端: &l ...

  9. mysql 使用注意

    1. consider upgrading MySQL client 描述:因mysql5版本过度到8版本后,访问要求升级mysql的客户端 原因:mysql在升级后,对加密算法部分做了调整导致. 对 ...

  10. 2018 pycharm最近激活码

    今天更新了一下pycharm,结果之前的激活就不能用了,下面是新的激活方法: 1.mac下在终端进入etc目录: cd /etc 2.编辑hosts文件: vi hosts 将“0.0.0.0 acc ...