From 378d64548f06f8cac1207d3a1aec35a51b53c81d Mon Sep 17 00:00:00 2001 From: Edgar Ivaskevicius Date: Tue, 13 Nov 2012 17:14:35 -0500 Subject: [PATCH 1/2] Extended IDBExecutor interface. Added more methods available in Dapper's SqlMapper to IDBExecutor interface and implementation. --- DapperWrapper/DapperWrapper.csproj | 132 ++++++++++++++-------------- DapperWrapper/GridReaderWrapper.cs | 54 ++++++++++++ DapperWrapper/IDbExecutor.cs | 49 ++++++++++- DapperWrapper/IGridReaderWrapper.cs | 14 +++ DapperWrapper/SqlExecutor.cs | 104 +++++++++++++++++++++- 5 files changed, 286 insertions(+), 67 deletions(-) create mode 100644 DapperWrapper/GridReaderWrapper.cs create mode 100644 DapperWrapper/IGridReaderWrapper.cs diff --git a/DapperWrapper/DapperWrapper.csproj b/DapperWrapper/DapperWrapper.csproj index 1ba2085..e542840 100644 --- a/DapperWrapper/DapperWrapper.csproj +++ b/DapperWrapper/DapperWrapper.csproj @@ -1,72 +1,74 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {0E94BB6B-8213-4B74-B362-A84D42B1AE5D} - Library - Properties - DapperWrapper - DapperWrapper - v4.0 - 512 - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Dapper.1.8\lib\net40\Dapper.dll - - - - - - - - - - - - - - - - - - - - - - Designer - - - - - + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {0E94BB6B-8213-4B74-B362-A84D42B1AE5D} + Library + Properties + DapperWrapper + DapperWrapper + v4.0 + 512 + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Dapper.1.8\lib\net40\Dapper.dll + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + + + + --> \ No newline at end of file diff --git a/DapperWrapper/GridReaderWrapper.cs b/DapperWrapper/GridReaderWrapper.cs new file mode 100644 index 0000000..ae53237 --- /dev/null +++ b/DapperWrapper/GridReaderWrapper.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using Dapper; + +namespace DapperWrapper +{ + class GridReaderWrapper : IGridReaderWrapper + { + private SqlMapper.GridReader _gridReader; + + public GridReaderWrapper(SqlMapper.GridReader gridReader) + { + _gridReader = gridReader; + } + + public IEnumerable Read() + { + return _gridReader.Read(); + } + + public IEnumerable Read( + Func func, + string splitOn = "id") + { + return _gridReader.Read(func, splitOn); + } + + public IEnumerable Read( + Func func, + string splitOn = "id") + { + return _gridReader.Read(func, splitOn); + } + + public IEnumerable Read( + Func func, + string splitOn = "id") + { + return _gridReader.Read(func, splitOn); + } + + public IEnumerable Read( + Func func, + string splitOn = "id") + { + return _gridReader.Read(func, splitOn); + } + + public void Dispose() + { + _gridReader.Dispose(); + } + } +} diff --git a/DapperWrapper/IDbExecutor.cs b/DapperWrapper/IDbExecutor.cs index 065efc4..415a0fd 100644 --- a/DapperWrapper/IDbExecutor.cs +++ b/DapperWrapper/IDbExecutor.cs @@ -27,6 +27,53 @@ IEnumerable Query( IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = default(int?), - CommandType? commandType = default(CommandType?)); + CommandType? commandType = default(CommandType?)); + + IEnumerable Query( + string sql, + Func map, + object param = null, + IDbTransaction transaction = null, + bool buffered = true, + string splitOn = "Id", + int? commandTimeout = default(int?), + CommandType? commandType = default(CommandType?)); + + IEnumerable Query( + string sql, + Func map, + object param = null, + IDbTransaction transaction = null, + bool buffered = true, + string splitOn = "Id", + int? commandTimeout = default(int?), + CommandType? commandType = default(CommandType?)); + + IEnumerable Query( + string sql, + Func map, + object param = null, + IDbTransaction transaction = null, + bool buffered = true, + string splitOn = "Id", + int? commandTimeout = default(int?), + CommandType? commandType = default(CommandType?)); + + IEnumerable Query( + string sql, + Func map, + object param = null, + IDbTransaction transaction = null, + bool buffered = true, + string splitOn = "Id", + int? commandTimeout = default(int?), + CommandType? commandType = default(CommandType?)); + + IGridReaderWrapper QueryMultiple( + string sql, + dynamic param = null, + IDbTransaction transaction = null, + int? commandTimeout = null, + CommandType? commandType = null); } } \ No newline at end of file diff --git a/DapperWrapper/IGridReaderWrapper.cs b/DapperWrapper/IGridReaderWrapper.cs new file mode 100644 index 0000000..f38bc34 --- /dev/null +++ b/DapperWrapper/IGridReaderWrapper.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace DapperWrapper +{ + public interface IGridReaderWrapper : IDisposable + { + IEnumerable Read(); + IEnumerable Read(Func func, string splitOn = "id"); + IEnumerable Read(Func func, string splitOn = "id"); + IEnumerable Read(Func func, string splitOn = "id"); + IEnumerable Read(Func func, string splitOn = "id"); + } +} diff --git a/DapperWrapper/SqlExecutor.cs b/DapperWrapper/SqlExecutor.cs index f98a730..8be5245 100644 --- a/DapperWrapper/SqlExecutor.cs +++ b/DapperWrapper/SqlExecutor.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using Dapper; @@ -61,6 +62,107 @@ public IEnumerable Query( buffered, commandTimeout, commandType); + } + + public IEnumerable Query( + string sql, + Func map, + object param = null, + IDbTransaction transaction = null, + bool buffered = true, + string splitOn = "Id", + int? commandTimeout = default(int?), + CommandType? commandType = default(CommandType?)) + { + return _sqlConnection.Query( + sql, + map, + param, + transaction, + buffered, + splitOn, + commandTimeout, + commandType); + } + + public IEnumerable Query( + string sql, + Func map, + object param = null, + IDbTransaction transaction = null, + bool buffered = true, + string splitOn = "Id", + int? commandTimeout = default(int?), + CommandType? commandType = default(CommandType?)) + { + return _sqlConnection.Query( + sql, + map, + param, + transaction, + buffered, + splitOn, + commandTimeout, + commandType); + } + + public IEnumerable Query( + string sql, + Func map, + object param = null, + IDbTransaction transaction = null, + bool buffered = true, + string splitOn = "Id", + int? commandTimeout = default(int?), + CommandType? commandType = default(CommandType?)) + { + return _sqlConnection.Query( + sql, + map, + param, + transaction, + buffered, + splitOn, + commandTimeout, + commandType); + } + + public IEnumerable Query( + string sql, + Func map, + object param = null, + IDbTransaction transaction = null, + bool buffered = true, + string splitOn = "Id", + int? commandTimeout = default(int?), + CommandType? commandType = default(CommandType?)) + { + return _sqlConnection.Query( + sql, + map, + param, + transaction, + buffered, + splitOn, + commandTimeout, + commandType); + } + + public IGridReaderWrapper QueryMultiple( + string sql, + object param = null, + IDbTransaction transaction = null, + int? commandTimeout = null, + CommandType? commandType = null) + { + var gridReader = _sqlConnection.QueryMultiple( + sql, + param, + transaction, + commandTimeout, + commandType); + + return new GridReaderWrapper(gridReader); } public void Dispose() From 11c5b13c4bb6c8234419d5fb85742708cbc11846 Mon Sep 17 00:00:00 2001 From: Edgar Ivaskevicius Date: Sat, 17 Nov 2012 22:20:04 -0500 Subject: [PATCH 2/2] Update Dapper dependency version to 1.12.1. --- DapperWrapper/DapperWrapper.csproj | 5 +++-- DapperWrapper/packages.config | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/DapperWrapper/DapperWrapper.csproj b/DapperWrapper/DapperWrapper.csproj index e542840..b492cf3 100644 --- a/DapperWrapper/DapperWrapper.csproj +++ b/DapperWrapper/DapperWrapper.csproj @@ -33,8 +33,9 @@ 4 - - ..\packages\Dapper.1.8\lib\net40\Dapper.dll + + False + ..\packages\Dapper.1.12.1\lib\net40\Dapper.dll diff --git a/DapperWrapper/packages.config b/DapperWrapper/packages.config index a685d00..706166d 100644 --- a/DapperWrapper/packages.config +++ b/DapperWrapper/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file