博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Dapper扩展之~~~Dapper.Contrib
阅读量:5961 次
发布时间:2019-06-19

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

平台之大势何人能挡? 带着你的Net飞奔吧!

上一篇文章:

 官方地址:

实战案例:(更新ing)

注意点:Model里面的Table和Key是Dapper.Contrib.Extensions命名空间下的~~~~如果不是~~请看下篇文章()

 

用法很简单,贴一下帮助类:

///     /// 扩展方法    ///     public abstract partial class DapperDataAsync    {        #region 查询系        ///         /// 获取Model-Key为int类型        ///         /// 
/// /// /// ///
public static async Task
GetAsync
(int id, IDbTransaction transaction = null, int? commandTimeout = null) where T : class, new() { using (var conn = ConnFactory.GetConnection()) { return await conn.GetAsync
(id, transaction, commandTimeout); } } ///
/// 获取Model-Key为long类型 /// ///
///
///
///
///
public static async Task
GetAsync
(long id, IDbTransaction transaction = null, int? commandTimeout = null) where T : class, new() { using (var conn = ConnFactory.GetConnection()) { return await conn.GetAsync
(id, transaction, commandTimeout); } } ///
/// 获取Model-Key为Guid类型 /// ///
///
///
///
///
public static async Task
GetAsync
(System.Guid id, IDbTransaction transaction = null, int? commandTimeout = null) where T : class, new() { using (var conn = ConnFactory.GetConnection()) { return await conn.GetAsync
(id, transaction, commandTimeout); } } ///
/// 获取Model-Key为string类型 /// ///
///
///
///
///
public static async Task
GetAsync
(string id, IDbTransaction transaction = null, int? commandTimeout = null) where T : class, new() { using (var conn = ConnFactory.GetConnection()) { return await conn.GetAsync
(id, transaction, commandTimeout); } } ///
/// 获取Model集合(没有Where条件) /// ///
///
public static async Task
> GetAllAsync
() where T : class, new() { using (var conn = ConnFactory.GetConnection()) { return await conn.GetAllAsync
(); } } #endregion #region 增删改 ///
/// 插入一个Model /// ///
///
///
///
///
///
public static async Task
InsertAsync
(T model, IDbTransaction transaction = null, int? commandTimeout = null) where T : class, new() { using (var conn = ConnFactory.GetConnection()) { return await conn.InsertAsync
(model, transaction, commandTimeout); } } ///
/// 更新一个Model /// ///
///
///
///
///
///
public static async Task
UpdateAsync
(T model, IDbTransaction transaction = null, int? commandTimeout = null) where T : class, new() { using (var conn = ConnFactory.GetConnection()) { bool b = await conn.UpdateAsync
(model, transaction, commandTimeout); if (b) { return model; } else { return null; } } } #endregion #region 分页查询 ///
/// 分页查询(为什么不用out,请参考:http://www.cnblogs.com/dunitian/p/5556909.html) /// ///
查询语句 ///
动态参数 ///
total语句 ///
Total动态参数 ///
public static async Task
PageLoadAsync
(string sql, object p = null, string sqlTotal = "", object p2 = null) { var rows = await QueryAsync
(sql.ToString(), p); var total = rows.Count(); if (!sqlTotal.IsNullOrWhiteSpace()) { total = await ExecuteScalarAsync
(sqlTotal, p2); } return new { rows = rows, total = total }.ObjectToJson(); } #endregion }

转载于:https://www.cnblogs.com/dunitian/p/5710382.html

你可能感兴趣的文章
阿里百川码力APP监控 来了!
查看>>
使用dotenv管理环境变量
查看>>
温故js系列(11)-BOM
查看>>
Vuex学习
查看>>
bootstrap - navbar
查看>>
切图崽的自我修养-[ES6] 编程风格规范
查看>>
服务器迁移小记
查看>>
FastDFS存储服务器部署
查看>>
Android — 创建和修改 Fragment 的方法及相关注意事项
查看>>
swift基础之_swift调用OC/OC调用swift
查看>>
Devexpress 15.1.8 Breaking Changes
查看>>
Java B2B2C多用户商城 springcloud架构- common-service 项目构建过程(七)
查看>>
杨老师课堂之ArrayList集合常用方法解析
查看>>
ElasticSearch Client详解
查看>>
新零售讲堂之时代下的传统零售业,何去何从?
查看>>
c++读取和写入TXT文件的整理
查看>>
linux安全问答(1)
查看>>
mybatis update返回值的意义
查看>>
expdp 详解及实例
查看>>
解读最具O2O属性—哈根达斯微信企业号的成功之道
查看>>