DBAutomator 0.2.0

Save and update objects to a database using only Linq.

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.
Install-Package DBAutomator -Version 0.2.0
dotnet add package DBAutomator --version 0.2.0
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.

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.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.11.0 62 1/29/2020
0.10.0 103 1/26/2020
0.9.0 91 1/18/2020
0.8.0 116 1/17/2020
0.7.0 89 1/15/2020
0.6.0 161 1/10/2020
0.5.0 118 1/6/2020
0.4.0 58 1/5/2020
0.3.0 76 12/15/2019
0.2.0 72 11/21/2019
0.1.0 70 11/10/2019
Show less