Open.Database.Extensions.Dataflow
6.6.2
See the version list below for details.
dotnet add package Open.Database.Extensions.Dataflow --version 6.6.2
NuGet\Install-Package Open.Database.Extensions.Dataflow -Version 6.6.2
<PackageReference Include="Open.Database.Extensions.Dataflow" Version="6.6.2" />
paket add Open.Database.Extensions.Dataflow --version 6.6.2
#r "nuget: Open.Database.Extensions.Dataflow, 6.6.2"
// Install Open.Database.Extensions.Dataflow as a Cake Addin #addin nuget:?package=Open.Database.Extensions.Dataflow&version=6.6.2 // Install Open.Database.Extensions.Dataflow as a Cake Tool #tool nuget:?package=Open.Database.Extensions.Dataflow&version=6.6.2
Open.Database.Extensions
Useful set of utilities and abstractions for simplifying modern database operations and ensuring dependency injection compatibility.
Full API Documentation Click Here
Connection Factories
Connection factories facilitate creation and disposal of connections without the concern of a connection reference or need for awareness of a connection string. A SqlConnectionFactory
is provided and can be overridden to provide more specific dependency injection configurations.
Expressive Commands
The provided expressive command classes allow for an expressive means to append parameters and execute the results without lengthy complicated setup.
Extensions are provided to create commands from connection factories.
Example
var result = connectionFactory
.StoredProcedure("[procedure name]")
.AddParam("a",1)
.AddParam("b",true)
.AddParam("c","hello")
.ExecuteScalar();
Asynchronous
End-to-end asynchronous methods suffixed with Async
.
When using the SQL Client, asynchronous methods are available as well as .ToTargetBlockAsync<T>(target)
and .AsSourceBlockAsync<T>()
Dataflow methods.
Extensions
Instead of writing this:
var myResult = new List<T>();
using(var reader = await mySqlCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection))
{
while(await reader.ReadAsync())
list.Add(transform(reader));
}
Is now simplified to this:
var myResult = await cmd.ToListAsync(transform);
Deferred Transformation
In order to keep connection open time to a minimum, some methods cache data before closing the connection and then subsequently applying the transformations as needed.
Results<T>()
and ResultsAsync<T>()
Queues all the data. Then using the provided type T
entity, the data is coerced by which properties intersect with the ones available to the IDataReader
.
Optionally a field to column override map can be passed as a parameter. If a column is set as null
then that field is ignored (not applied to the model).
Examples
If all the columns in the database map exactly to a field: (A column that has no associated field/property is ignored.)
var people = cmd.Results<Person>();
If the database fields don't map exactly:
var people = cmd.Results<Person>(
(Field:"FirstName", Column:"first_name"),
(Field:"LastName", Column:"last_name")));
or
var people = cmd.Results<Person>(
("FirstName", "first_name"),
("LastName", "last_name"));
or
var people = cmd.Results<Person>(new Dictionary<string,string>{
{"FirstName", "first_name"},
{"LastName", "last_name"});
Retrieve()
and RetrieveAsync()
Queues all the data. Returns a QueryResult<Queue<object[]>>
containing the requested data and column information. The .AsDequeueingMappedEnumerable()
extension will iteratively convert the results to dictionaries for ease of access.
AsSourceBlockAsync<T>()
Include the Open.Database.Extensions.Dataflow
package for Dataflow extensions.
(Fully asynchronous.) Returns a Dataflow source block. Then asynchronously buffers and transforms the results allowing for any possible Dataflow configuration. The source block is marked as complete when there are no more results. If the block is somehow marked as complete externally, the flow of data will stop and the connection will close.
AsSourceBlockAsync<T>()
versus ResultsAsync<T>
Depending on the level of asynchrony in your application, you may want to avoid too much buffering of data.
AsSourceBlockAsync<T>()
is fully asynchronous from end-to-end and can keep total buffering to a minimum by consuming (receiving) results as fast as possible, but may incur additional latency between reads.
ResultsAsync<T>()
is fully asynchronous from end-to-end but returns an IEnumerable<T>
that although has fully buffered the all the data into memory, has deferred the transformation until enumerated. This way, the asynchronous data pipeline is fully complete before synchronously transforming the data.
Both methods ultimately are using a Queue<object[]>
or ConcurrentQueue<object[]>
(Dataflow) to buffer the data, but ResultsAsync<T>()
buffers the entire data set before dequeuing and transforming the results.
Transactions
Example:
// 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 committed.
// If it returns false, then the transaction is rolled back.
return transaction
.StoredProcedure("[Validation Procedure]")
.AddParam("@ExpectedCount", count)
.ExecuteScalar<bool>();
}));
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Open.Database.Extensions.Core (>= 6.6.2)
- System.Threading.Tasks.Dataflow (>= 4.11.1)
-
.NETStandard 2.1
- Open.Database.Extensions.Core (>= 6.6.2)
- System.Threading.Tasks.Dataflow (>= 4.11.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Open.Database.Extensions.Dataflow:
Package | Downloads |
---|---|
Open.Database.Extensions
Useful set of utilities and abstractions for simplifying modern data-access operations and ensuring DI compatibility. This now is a meta-package containing a collection of extensions. |
GitHub repositories
This package is not used by any popular GitHub repositories.