Package | Latest | |
---|---|---|
DBBroker | .NET Standard 2.0 | |
DBBroker.Cli |
IMPORTANT: This version has no backward compatibility with DBBroker 1.x and 2.x.
Differently from another popular ORM packages, DBBroker approach associates a .NET CLI tool to automatically generate Data Models and a library that uses those Data Models at runtime to manipulate database records.
DBBroker offers features that benefit any kind of application, from the simplest to the most complex, particularly in security-restricted scenarios. Here are some key requirements it addresses:
-
Applications should NOT be responsible for executing DDL.
-
Applications' Data Access Objects should act as clients to the database, not the other way around.
-
Schema Migrations are not an option due to a development process led by Database Administrators.
These are common requirements for many organizations or database-centered solutions, and, arguably, by everyone who likes to keep things simple.
Open your terminal and navigate to your application's *.csproj directory. Then follow these steps:
Step 1: Install DBBroker.Cli
.NET tool globally.
dotnet tool install DBBroker.Cli --global
Step 2: Add DBBroker
package to your project.
dotnet nuget add DBBroker
Step 3: Create a dbbroker.config.json
file at the root of your project.
dbbroker init --namespace="MyApp.DataModels" --connection-string "[database-connection-string]" --provider Oracle
Step 4: Synchronize your project with your database schemas to generate the Data Models.
dbbroker sync
Entity persistence.
// Data Models classes are generated by DBBroker (dbbroker sync)
var customer = new CustomersDataModel();
customer.Name = "John Three Sixteen";
customer.Birthday = new DateTime(1980, 3, 16);
var id = await _dbBroker.InsertAsync(customer);
Entity persistence with transactions.
using var connection = new SqlConnection();
connection.Open();
var transaction = connection.GetTransaction();
try
{
var customer = new CustomersDataModel();
customer.Id = Guid.NewGuid();
customer.Name = "John Three Sixteen";
customer.Birthday = new DateTime(1980, 3, 16);
await connection.InsertAsync(customer, transaction);
var car = new CarEdm();
car.Model = "Renault Twingo";
car.Year = 2001;
car.CustomerId = customer.Id;
await connection.InsertAsync(car, transaction);
transaction.Commit();
}
catch(Exception ex)
{
transaction.Rollback();
}
Retrieving a record.
var customer = await connection.GetByKey<CustomersDataModel>("543491fa-788a-474c-9f3b-6ed6566e5d2c");
Retrieving multiple and filtered records.
var inactiveCustomers = await connection.Select<CustomersDataModel>()
.AddFilter(x => x.StatusId, SqlEquals.To(3))
.FetchFirst(records: 100, skip: 300) // helps implement a 'load more' or pagination strategy
.ExecuteAsync();
// another example with columns
// another example with columns and order by
Database | Status | --provider |
---|---|---|
SQL Server | ✅ | SqlServer |
Oracle | ✅ | Oracle |
Postgres | ⚒️ | Postgres |
MySQL | 🛣️ | MySql |
We appreciate all contributions, whether they're bug reports, feature suggestions, or pull requests. Thank you for your interest and support in improving this project!
Financial support is also welcome, whether large or small contributions will help to keep this project moving and always secure.