博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Dapper基础知识二
阅读量:6934 次
发布时间:2019-06-27

本文共 3252 字,大约阅读时间需要 10 分钟。

在下刚毕业工作,之前实习有用到Dapper?这几天新项目想用上Dapper,在下比较菜鸟,这块只是个人对Dapper的一种总结。

2,如何使用Dapper?

    首先Dapper是支持多种数据库的,当时在学习的时候参考蓝老师的资料https://www.cnblogs.com/lanxiaoke/p/6503022.html。

     Dapper支持多数据库的工厂类,设计模式的工厂模式,Skr·  Skr~。

public interface IRepository
where T : class { void Add(T entity); void AddBatch(IEnumerable
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); IEnumerable
GetAll(); IEnumerable
GetList(Expression
> where = null, Expression
> order = null); Tuple
> GetPage(Page page, Expression
> where = null, Expression
> order = null); long Count(Expression
> where = null); }

 

public class IDapperRepository
:IRepository
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
(entity); } public void AddBatch(IEnumerable
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
(entity); } public T Get(Guid Id) { return Conn.Get
(Id); } public T Get(string Id) { return Conn.Get
(Id); } public T Get(int Id) { return Conn.Get
(Id); } public T Get(Expression
> func) { throw new NotImplementedException(); } public IEnumerable
GetAll() { throw new NotImplementedException(); } public IEnumerable
GetList(Expression
> where = null, Expression
> order = null) { throw new NotImplementedException(); } public Tuple
> GetPage(Page page, Expression
> where = null, Expression
> order = null) { throw new NotImplementedException(); } public long Count(Expression
> where = null) { throw new NotImplementedException(); } }

 

   

 由于Dapper是对Sqlmapper的扩展,所以当引入Dapper或者Dapper的扩展类之后,实例化IDbConnection 就可以使用上面的Dapper已经封装好的方法了。

具体Dapper如何使用可看上一篇的小白的参考资料

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

 

以上就是对Dapper的初级使用了。

 

 

转载于:https://www.cnblogs.com/MasterLin/p/10041167.html

你可能感兴趣的文章
微服务开源项目ServiceComb 毕业成为Apache顶级项目
查看>>
ThoughtWorks雷达上的新奇变化
查看>>
《可扩展的艺术》内容回顾与作者采访
查看>>
Java 9推迟6个月发布?
查看>>
Spark 2.4重磅发布:优化深度学习框架集成,提供更灵活的流式接收器
查看>>
年终总结,程序员票选最喜欢的编程语言花落谁家?
查看>>
Reinhold就Jigsaw投票一事向JCP提交公开信
查看>>
Spark、Flink、CarbonData技术实践最佳案例解析
查看>>
你在过度测试你的软件吗?
查看>>
慎用!BLEU评价NLP文本输出质量存在严重问题
查看>>
AppDynamics把业务交易跟踪扩展到SAP环境
查看>>
历时三年,美图全面容器化踩过的坑
查看>>
2018年终盘点:我们处在一个什么样的技术浪潮当中?
查看>>
IBM发布全球首台商用量子计算机
查看>>
在一个成熟的分布式系统中 如何下手做高可用?
查看>>
CoreOS 和 Kubernetes 1.5 自主运行 Kubernetes、Container Linux
查看>>
The only supported ciphers are AES-128-CBC and AES-256-CBC
查看>>
sphinx 全文搜索引擎
查看>>
Kotlin成为正式的Android编程语言
查看>>
物联网技术周报第 141 期: 使用 Alexa Voice 和 Raspberry Pi 构建图片识别应用
查看>>