Dapper基础知识二
在下刚毕业工作,之前实习有用到Dapper?这几天新项目想用上Dapper,在下比较菜鸟,这块只是个人对Dapper的一种总结。
2,如何使用Dapper?
首先Dapper是支持多种数据库的,当时在学习的时候参考蓝老师的资料https://www.cnblogs.com/lanxiaoke/p/6503022.html。
Dapper支持多数据库的工厂类,设计模式的工厂模式,Skr· Skr~。
public interface IRepository<T> where T : class
{
void Add(T entity);
void AddBatch(IEnumerable<T> entitys);
void Update(T entity);
void Delete(T entity);
void Delete(string Id);
void Delete(int Id);
void Delete(Guid Id);
T Get(string Id);
T Get(Guid Id);
T Get(int Id);
T Get(T entity);
T Get(Expression<Func<T, bool>> func);
IEnumerable<T> GetAll();
IEnumerable<T> GetList(Expression<Func<T, bool>> where = null, Expression<Func<T, bool>> order = null);
Tuple<int, IEnumerable<T>> GetPage(Page page, Expression<Func<T, bool>> where = null, Expression<Func<T, bool>> order = null);
long Count(Expression<Func<T, bool>> where = null);
}
public class IDapperRepository<T> :IRepository<T> where T:class
{
protected IDbConnection Conn { get; private set; }
public IDapperRepository()
{
Conn = DbConnectionFactory.CreateDbConnection();
}
public void SetDbConnection(IDbConnection conn)
{
Conn = conn;
} public void Add(T entity)
{ Conn.Insert<T>(entity);
} public void AddBatch(IEnumerable<T> entitys)
{
foreach (T entity in entitys)
{
Add(entity);
}
} public void Update(T entity)
{
Conn.Update(entity);
} public void Delete(T entity)
{
Conn.Delete(entity);
} public void Delete(string Id)
{
var entity = Get(Id);
if (entity == null)
return;
Delete(entity);
} public void Delete(int Id)
{
var entity = Get(Id);
if (entity == null) return; Delete(entity);
} public void Delete(Guid Id)
{
var entity = Get(Id);
if (entity == null) return; Delete(entity);
} public T Get(T entity)
{
return Conn.Get<T>(entity);
} public T Get(Guid Id)
{
return Conn.Get<T>(Id);
} public T Get(string Id)
{
return Conn.Get<T>(Id);
} public T Get(int Id)
{
return Conn.Get<T>(Id);
} public T Get(Expression<Func<T, bool>> func)
{
throw new NotImplementedException();
} public IEnumerable<T> GetAll()
{
throw new NotImplementedException();
} public IEnumerable<T> GetList(Expression<Func<T, bool>> where = null, Expression<Func<T, bool>> order = null)
{
throw new NotImplementedException();
} public Tuple<int, IEnumerable<T>> GetPage(Page page, Expression<Func<T, bool>> where = null, Expression<Func<T, bool>> order = null)
{
throw new NotImplementedException();
} public long Count(Expression<Func<T, bool>> where = null)
{
throw new NotImplementedException();
}
}
由于Dapper是对Sqlmapper的扩展,所以当引入Dapper或者Dapper的扩展类之后,实例化IDbConnection 就可以使用上面的Dapper已经封装好的方法了。
具体Dapper如何使用可看上一篇的小白的参考资料

具体的方法可以查看引用的对象浏览器


以上就是对Dapper的初级使用了。
Dapper基础知识二的更多相关文章
- Dapper基础知识三
在下刚毕业工作,之前实习有用到Dapper?这几天新项目想用上Dapper,在下比较菜鸟,这块只是个人对Dapper的一种总结. Dapper,当项目在开发的时候,在没有必要使用依赖注入的时候,如何做 ...
- Dapper基础知识一
在下刚毕业工作,之前实习有用到Dapper?这几天新项目想用上Dapper,在下比较菜鸟,这块只是个人对Dapper的一种总结. 1,什么是Dapper? Dapper,.NET下的一种ORM ...
- java 基础知识二 基本类型与运算符
java 基础知识二 基本类型与运算符 1.标识符 定义:为类.方法.变量起的名称 由大小写字母.数字.下划线(_)和美元符号($)组成,同时不能以数字开头 2.关键字 java语言保留特殊含义或者 ...
- 菜鸟脱壳之脱壳的基础知识(二) ——DUMP的原理
菜鸟脱壳之脱壳的基础知识(二)——DUMP的原理当外壳的执行完毕后,会跳到原来的程序的入口点,即Entry Point,也可以称作OEP!当一般加密强度不是很大的壳,会在壳的末尾有一个大的跨段,跳向O ...
- python基础知识(二)
python基础知识(二) 字符串格式化 格式: % 类型 ---- > ' %类型 ' %(数据) %s 字符串 print(' %s is boy'%('tom')) ----> ...
- Java基础知识二次学习--第三章 面向对象
第三章 面向对象 时间:2017年4月24日17:51:37~2017年4月25日13:52:34 章节:03章_01节 03章_02节 视频长度:30:11 + 21:44 内容:面向对象设计思 ...
- Java基础知识二次学习-- 第一章 java基础
基础知识有时候感觉时间长似乎有点生疏,正好这几天有时间有机会,就决定重新做一轮二次学习,挑重避轻 回过头来重新整理基础知识,能收获到之前不少遗漏的,所以这一次就称作查漏补缺吧!废话不多说,开始! 第一 ...
- 快速掌握JavaScript面试基础知识(二)
译者按: 总结了大量JavaScript基本知识点,很有用! 原文: The Definitive JavaScript Handbook for your next developer interv ...
- Java基础知识二次学习--第六章 常用类
第六章 常用类 时间:2017年4月26日16:14:49~2017年4月26日16:56:02 章节:06章_01节~06章_06节 视频长度:20:57+1:15+8:44+1:26+11:2 ...
随机推荐
- Hibernate框架学习(六)——一对多&多对一关系
一.关系表达 1.表中的表达 2.实体中的表达 3.orm元数据中的表达 一对多:(在Customer.hbm.xml中添加) 多对一:(在LinkMan.hbm.xml中添加) 最后别忘了在hibe ...
- wechat4j开发所有jar包
wechat4j开发所需要的jar包合计,不用你去单独下载,已经全部包括 下载连接 wechat4j-lib.rar 如果你的服务是部署在新浪云计算SAE上的,那么下载这个jar合集 wechat4j ...
- Thingworx 使用REST API获取JSON数据
版本:7.4.1 1.URL规则 http://localhost/Thingworx/Things/[Things名称]/Services/[Service名称]?method=POST&A ...
- Hihocoder1061-Beautiful String
时间限制:10000ms单点时限:1000ms内存限制:256MB 描述 We say a string is beautiful if it has the equal amount of 3 or ...
- mybatis中if及concat函数的使用
- 洛谷1613 跑路 倍增 + Floyd
首先,我们一定要认识到本题中的最短时间所对应的道路不一定是在起点到终点的最短路.例如,起点到终点的最短路为 151515 ,那么对 151515 进行二进制拆分的话是 111111111111 ,这时 ...
- kernel zram feature
what is zram? Zram wiki zram zram(也称为 zRAM,先前称为 compcache)是 Linux 内核的一项功能,可提供虚拟内存压缩.zram 通过在 RAM 内的压 ...
- Git:与eclipse搭配使用
Git:与eclipse搭配使用 1)工程初始化为本地库 工程 ——>右键 ——>Team ——Share Project 在该目录下创建了本地库 这里可以设置用户签名 2)Eclipse ...
- jsonp实现原理
jquery 封装在 ajax方法 里面的jsonp jsonp跨域的原理 1:使用script 标签发送请求,这个标签支持跨域访问 2:在script 标签里面给服务器端传递 ...
- 解决ORA-28002: 密码7天之后过期办法
https://www.douban.com/group/topic/46177516/ https://yq.aliyun.com/ziliao/42484 http://blog.csdn.net ...