DBAutomator 0.2.0

Suggested Alternatives

Dapper.SqlWriter

Additional Details

DBAutomator was renamed to Dapper.SqlWriter

There is a newer version of this package available.
See the version list below for details.
dotnet add package DBAutomator --version 0.2.0
NuGet\Install-Package DBAutomator -Version 0.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DBAutomator" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DBAutomator --version 0.2.0
#r "nuget: DBAutomator, 0.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DBAutomator as a Cake Addin
#addin nuget:?package=DBAutomator&version=0.2.0

// Install DBAutomator as a Cake Tool
#tool nuget:?package=DBAutomator&version=0.2.0

devhl.DBAutomator

This .NET Standard 2.1 library allows you to easily save and retrieve your objects from a database.

Test Program

Begin by instantiating a QueryOptions object, and pass that into the DBAutomator class. Then register your database POCO classes with the library.

QueryOptions queryOptions = new QueryOptions
{
    DataStore = DataStore.PostgreSQL,          
};

queryOptions.ConnectionString = $"Server=127.0.0.1;Port=5432;Database=AutomatorTest;User ID=postgres;Password={password};";

DBAutomator postgres = new DBAutomator(queryOptions, logService);

postgres.Register(new UserModel());
postgres.Register(new AddressModel());
postgres.Register(new UserAddressModel());

Now you can save and retrieve your objects using Linq.

//delete all rows in the table
var a = await postgres.DeleteAsync<UserModel>();

//insert a new row
var b = await postgres.InsertAsync(newUser1);

//update an existing row
newUser1.UserName = "changed";
var h = await postgres.UpdateAsync(newUser1);

//update all matching rows
var i = await postgres.UpdateAsync<UserModel>(u => u.UserName == "changed again", u => u.UserName == "changed");

//get the required rows
var j = await postgres.GetAsync<UserModel>(u => u.UserID > 2);
var n = await postgres.GetAsync<UserModel>(u => u.UserID == 2);
var o = await postgres.GetAsync<UserModel>(u => u.UserID == 2 || u.UserName == "changed again");
var p = await postgres.GetAsync(u => u.UserID == 2 || u.UserName == "changed again", orderBy);

Configuring Your Classes

The Register method returns a RegisteredClass object. You may edit the TableName and ColumnName properties to point your class to the property database object. You may also decorate your class with attributes. This library uses five attributes from Entity Framework: Key, NotMapped, Table, Column, and DatabaseGenerated. The option you provide to the DatabaseGenereated is not relevant. The library will also work with views so you can easily get joins working.

IDBObject

Your classes can optionally implement the IDBObject interface. This will add call backs in your POCO when the library inserts, updates, deletes, or selects your object.

Compatibility

This library is tested with PostgreSQL but it may work with other databases as well. The table definitions used while testing can be found in the UserModel, AddressModel, and UserAddressModel files. The generated SQL is printed to the ILogger.Trace method.

Product 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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
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
0.11.0 626 1/29/2020
0.10.0 623 1/26/2020
0.9.0 574 1/18/2020
0.8.0 596 1/17/2020
0.7.0 562 1/15/2020
0.6.0 685 1/10/2020
0.5.0 600 1/6/2020
0.4.0 547 1/5/2020
0.3.0 559 12/15/2019
0.2.0 572 11/21/2019
0.1.0 545 11/10/2019