ABP框架系列之十六:(Dapper-Integration-Dapper集成)
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集成)的更多相关文章
- ABP框架系列之四十六:(Setting-Management-设置管理)
Introduction Every application need to store some settings and use these settings in somewhere in th ...
- ABP框架系列之三十六:(MVC-Views-MVC视图)
Introduction ASP.NET Boilerplate is integrated to MVC Views via Abp.Web.Mvc nuget package. You can c ...
- ABP框架系列之五十四:(XSRF-CSRF-Protection-跨站请求伪造保护)
Introduction "Cross-Site Request Forgery (CSRF) is a type of attack that occurs when a maliciou ...
- ABP框架系列之三十四:(Multi-Tenancy-多租户)
What Is Multi Tenancy? "Software Multitenancy refers to a software architecture in which a sing ...
- ABP框架系列之三十八:(NHibernate-Integration-NHibernate-集成)
ASP.NET Boilerplate can work with any O/RM framework. It has built-in integration with NHibernate. T ...
- ABP框架系列之三十九:(NLayer-Architecture-多层架构)
Introduction Layering of an application's codebase is a widely accepted technique to help reduce com ...
- ABP框架系列之四十九:(Startup-Configuration-启动配置)
ASP.NET Boilerplate provides an infrastructure and a model to configure it and modules on startup. A ...
- ABP框架系列之十五:(Caching-缓存)
Introduction ASP.NET Boilerplate provides an abstraction for caching. It internally uses this cache ...
- ABP框架系列之三十二:(Logging-登录)
Server Side(服务端) ASP.NET Boilerplate uses Castle Windsor's logging facility. It can work with differ ...
随机推荐
- SQLServer数据库镜像配置
目录 一.目标...2 二.前提条件.限制和建议...2 三.设置概述...2 四.安装Sql Server 2008 enterprise X64.3 4.1.安装.NET3.5.3 4.2.安装时 ...
- 使用IntelliJ IDEA创建简单的Dubbo实例
这个博客是在https://blog.csdn.net/Crazer_cy/article/details/80397649篇文章上的基础上,自己学习用的. Zookeeper为dubbo的注册中心, ...
- 谈谈线上CPU100%排查套路
知识点总结 ---------------------------------------------------------------------------------------------- ...
- [UnityAPI]SerializedObject类 & SerializedProperty类
以Image类为例 1.MyImage.cs using UnityEngine; using UnityEngine.UI; public class MyImage : Image { ; pro ...
- CentOS 7 实现ssh无密码登录
cd ~ 进入根目录. (使用ls -a或者 ls -la 能够看到当前文件夹下的所有文件包含隐藏文件夹等) 我们首先使用ls -la 发现并没有.ssh的文件夹存在. 在终端输入 ssh lo ...
- python3 互译无线短信接口
#!/usr/local/bin/python#-*- coding:utf-8 -*-import http.clientimport urllibimport random host = &quo ...
- logback的使用和logback.xml详解,在Spring项目中使用log打印日志
logback的使用和logback.xml详解 一.logback的介绍 Logback是由log4j创始人设计的另一个开源日志组件,官方网站: http://logback.qos.ch.它当前分 ...
- 转载:c++深拷贝和浅拷贝
文章来自:http://blog.csdn.net/u010700335/article/details/39830425 C++中类的拷贝有两种:深拷贝,浅拷贝:当出现类的等号赋值时,即会调用拷贝函 ...
- MySQL master-slave主从复制环境搭建初试
环境为centos 7.2+mysql 5.7,网上教程很多,原理也不复杂(深知自己踩的坑还不够) 正常情况下,配置起来比较简单.另外,根据个人感受,MySQL的复制感觉要比SQL Server的复制 ...
- pyspider示例代码:解析JSON数据
pyspider示例代码官方网站是http://demo.pyspider.org/.上面的示例代码太多,无从下手.因此本人找出一下比较经典的示例进行简单讲解,希望对新手有一些帮助. 示例说明: py ...