Open.Database.Extensions 7.0.0

.NET Standard 2.0
Install-Package Open.Database.Extensions -Version 7.0.0
dotnet add package Open.Database.Extensions --version 7.0.0
<PackageReference Include="Open.Database.Extensions" Version="7.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Open.Database.Extensions --version 7.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Open.Database.Extensions, 7.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Open.Database.Extensions as a Cake Addin
#addin nuget:?package=Open.Database.Extensions&version=7.0.0

// Install Open.Database.Extensions as a Cake Tool
#tool nuget:?package=Open.Database.Extensions&version=7.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Open.Database.Extensions

NuGet

Useful set of utilities and abstractions for simplifying modern database operations and ensuring dependency injection compatibility.

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();

Extensions

Instead of writing this:

var myResult = new List<T>();
using(var reader = await mySqlCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection))
{
    while(await reader.ReadAsync())
        myResult.Add(transform(reader));
}

Is now simplified to this:

var myResult = await mySqlCommand.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.

ResultsAsync<T>

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.

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
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.0.0 98 3/1/2022
6.6.2 357 7/16/2020
5.14.0 407 3/17/2019
5.13.3 529 10/23/2018
5.11.0 607 4/19/2018
5.10.0 626 4/17/2018
5.9.1 724 4/3/2018
5.8.0 818 3/31/2018
5.4.3 609 3/6/2018
5.4.1 628 2/21/2018
4.0.0 626 2/8/2018
3.1.1 725 2/5/2018
3.0.1 722 1/16/2018
2.2.0 707 1/16/2018
1.1.2 731 1/12/2018