-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented correct transaction flow. Added extensions for creating commands from transactions. Expanded expressive commands to allow for transactions. Added examples.
- Loading branch information
electricessence
committed
Apr 1, 2018
1 parent
02341c3
commit 15f086f
Showing
27 changed files
with
8,560 additions
and
1,522 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Open.Database.Extensions.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,30 @@ | ||
using Open.Database.Extensions; | ||
using System.Data.SqlClient; | ||
|
||
public static partial class Examples | ||
{ | ||
public readonly static DbConnectionFactory ConnectionFactory | ||
= new DbConnectionFactory(()=>new SqlConnection()); | ||
|
||
// Returns true if the transaction is successful. | ||
public static bool TryTransaction() | ||
=> ConnectionFactory.Using(connection => | ||
// Open a connection and start a transaction. | ||
connection.ExecuteTransactionConditional(transaction => { | ||
|
||
// First procedure does some updates. | ||
var count = transaction | ||
.StoredProcedure("[Updated Procedure]") | ||
.ExecuteNonQuery(); | ||
|
||
// Second procedure validates the results. | ||
// If it returns true, then the transaction is commited. | ||
// If it returns false, then the transaction is rolled back. | ||
return transaction | ||
.StoredProcedure("[Validation Procedure]") | ||
.AddParam("@ExpectedCount", count) | ||
.ExecuteScalar<bool>(); | ||
})); | ||
|
||
} | ||
|
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
Oops, something went wrong.