This repository has been archived by the owner on Nov 3, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
185 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ bin | |
obj | ||
*.user | ||
*.suo | ||
DbExecutor*.nupkg | ||
DapperWrapper*.nupkg | ||
_ReSharper* | ||
packages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
$scriptPath = Split-Path $MyInvocation.MyCommand.Path | ||
$projFile = Join-Path $scriptPath DbExecutor.msbuild | ||
$projFile = Join-Path $scriptPath DapperWrapper.msbuild | ||
|
||
& "$(get-content env:windir)\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" $projFile /p:Configuration=Release /t:Package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
$scriptPath = Split-Path $MyInvocation.MyCommand.Path | ||
$projFile = Join-Path $scriptPath DbExecutor.msbuild | ||
$projFile = Join-Path $scriptPath DapperWrapper.msbuild | ||
|
||
& "$(get-content env:windir)\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" $projFile /p:Configuration=Release /t:Build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
|
||
namespace DapperWrapper | ||
{ | ||
public interface IDbExecutor : IDisposable | ||
{ | ||
int Execute( | ||
string sql, | ||
object param = null, | ||
IDbTransaction transaction = null, | ||
int? commandTimeout = default(int?), | ||
CommandType? commandType = default(CommandType?)); | ||
|
||
IEnumerable<dynamic> Query( | ||
string sql, | ||
object param = null, | ||
IDbTransaction transaction = null, | ||
bool buffered = true, | ||
int? commandTimeout = default(int?), | ||
CommandType? commandType = default(CommandType?)); | ||
|
||
IEnumerable<T> Query<T>( | ||
string sql, | ||
object param = null, | ||
IDbTransaction transaction = null, | ||
bool buffered = true, | ||
int? commandTimeout = default(int?), | ||
CommandType? commandType = default(CommandType?)); | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
DbExecutor/IDbExecutorFactory.cs → DapperWrapper/IDbExecutorFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
| ||
namespace DbExecutor | ||
namespace DapperWrapper | ||
{ | ||
public interface IDbExecutorFactory | ||
{ | ||
IDbExecutor CreateExecutor(); | ||
ITransactionScope CreateTransactionScope(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
DbExecutor/ITransactionScope.cs → DapperWrapper/ITransactionScope.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
using Dapper; | ||
|
||
namespace DapperWrapper | ||
{ | ||
public class SqlExecutor : IDbExecutor | ||
{ | ||
readonly SqlConnection _sqlConnection; | ||
|
||
public SqlExecutor(SqlConnection sqlConnection) | ||
{ | ||
_sqlConnection = sqlConnection; | ||
} | ||
|
||
public int Execute( | ||
string sql, | ||
object param = null, | ||
IDbTransaction transaction = null, | ||
int? commandTimeout = default(int?), | ||
CommandType? commandType = default(CommandType?)) | ||
{ | ||
return _sqlConnection.Execute( | ||
sql, | ||
param, | ||
transaction, | ||
commandTimeout, | ||
commandType); | ||
} | ||
|
||
public IEnumerable<dynamic> Query( | ||
string sql, | ||
object param = null, | ||
IDbTransaction transaction = null, | ||
bool buffered = true, | ||
int? commandTimeout = default(int?), | ||
CommandType? commandType = default(CommandType?)) | ||
{ | ||
return _sqlConnection.Query( | ||
sql, | ||
param, | ||
transaction, | ||
buffered, | ||
commandTimeout, | ||
commandType); | ||
} | ||
|
||
public IEnumerable<T> Query<T>( | ||
string sql, | ||
object param = null, | ||
IDbTransaction transaction = null, | ||
bool buffered = true, | ||
int? commandTimeout = default(int?), | ||
CommandType? commandType = default(CommandType?)) | ||
{ | ||
return _sqlConnection.Query<T>( | ||
sql, | ||
param, | ||
transaction, | ||
buffered, | ||
commandTimeout, | ||
commandType); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_sqlConnection.Dispose(); | ||
} | ||
} | ||
} |
18 changes: 4 additions & 14 deletions
18
DbExecutor/SqlExecutorFactory.cs → DapperWrapper/SqlExecutorFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,24 @@ | ||
using System; | ||
using System.Data.SqlClient; | ||
using System.Transactions; | ||
|
||
namespace DbExecutor | ||
namespace DapperWrapper | ||
{ | ||
public class SqlExecutorFactory : IDbExecutorFactory | ||
{ | ||
readonly string connectionString; | ||
readonly string _connectionString; | ||
|
||
public SqlExecutorFactory(string connectionString) | ||
{ | ||
if (string.IsNullOrWhiteSpace(connectionString)) | ||
throw new ArgumentNullException("connectionString"); | ||
|
||
this.connectionString = connectionString; | ||
_connectionString = connectionString; | ||
} | ||
|
||
public IDbExecutor CreateExecutor() | ||
{ | ||
var dbConnection = new SqlConnection(connectionString); | ||
|
||
var dbConnection = new SqlConnection(_connectionString); | ||
dbConnection.Open(); | ||
|
||
return new SqlExecutor(dbConnection); | ||
} | ||
|
||
|
||
public ITransactionScope CreateTransactionScope() | ||
{ | ||
return new TransactionScopeWrapper(new TransactionScope()); | ||
} | ||
} | ||
} |
12 changes: 6 additions & 6 deletions
12
DbExecutor/TransactionScopeWrapper.cs → DapperWrapper/TransactionScopeWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
using System.Transactions; | ||
|
||
namespace DbExecutor | ||
namespace DapperWrapper | ||
{ | ||
public class TransactionScopeWrapper : ITransactionScope | ||
{ | ||
readonly TransactionScope transactionScope; | ||
readonly TransactionScope _transactionScope; | ||
|
||
public TransactionScopeWrapper(TransactionScope transactionScope) | ||
{ | ||
this.transactionScope = transactionScope; | ||
_transactionScope = transactionScope; | ||
} | ||
|
||
public void Complete() | ||
{ | ||
transactionScope.Complete(); | ||
_transactionScope.Complete(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
transactionScope.Dispose(); | ||
_transactionScope.Dispose(); | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.