A lightweight and easy to use .NET tool and library for effortless database records manipulation.
- Automatically generated Data Models
- Zero-SQL
- Compile time database schemas compatibility and change check
| Package | Latest | |
|---|---|---|
| DBBroker | .NET Standard 2.0 | |
| DBBroker.Cli |
Warning
Version 3.x has no backward compatibility with DBBroker 1.x and 2.x
DBBroker approach is powerful and different from other ORMs because it associates a .NET CLI tool to automatically generate Data Models and a library that uses those Data Models at runtime to generate SQL and manipulate database records.
DBBroker offers features that benefit any kind of .NET application that interacts with databases, from the simplest to the most complex, particularly in security-restricted scenarios. Here are some key requirements it addresses that other ORMs fail:
-
Applications should NOT be 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 --globalStep 2: Add DBBroker package to your project.
dotnet nuget add DBBrokerStep 3: Create a dbbroker.config.json file at the root of your project.
dbbroker init --namespace="MyApp.DataModels" --connection-string "<my_connection_string>" --provider OracleStep 4: Synchronize your project with your database schemas to generate the Data Models.
dbbroker syncEntity 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 dbConnection.InsertAsync(customer);Entity persistence with transactions.
using var dbConnection = new SqlConnection();
dbConnection.Open();
var transaction = dbConnection.GetTransaction();
try
{
var customer = new CustomersDataModel();
customer.Id = Guid.NewGuid();
customer.Name = "John Three Sixteen";
customer.Birthday = new DateTime(1980, 3, 16);
await dbConnection.InsertAsync(customer, transaction);
var car = new CarsDataModel();
car.Model = "Renault Twingo";
car.Year = 2001;
car.CustomerId = customer.Id;
await dbConnection.InsertAsync(car, transaction);
transaction.Commit();
}
catch(Exception ex)
{
transaction.Rollback();
}Retrieving a record.
var result = await dbConnection
.Select<CustomersDataModel>()
.AddFilter(x => x.Id, SqlEquals.To("1e6fc0e6-1fe2-49c0-ba37-ec14bf8eddc4"))
.ExecuteAsync();
var customer = result.FirstOrDefault();Retrieving multiple and filtered records.
var inactiveCustomers = await dbConnection.Select<CustomersDataModel>()
.AddFilter(x => x.StatusId, SqlEquals.To(3))
.ExecuteAsync();Retrieving multiple records loading only specified columns.
var inactiveCustomers = await dbConnection
.Select<CustomersDataModel>([
x => x.Id,
x => x.Name,
x => x.Birthday
])
.OrderBy(x => x.Name)
.AddFilter(x => x.StatusId, SqlEquals.To(3))
.ExecuteAsync();| Database | Status | --provider |
|---|---|---|
| SQL Server | ✅ | SqlServer |
| Oracle | ✅ | Oracle |
| Postgres | ⚒️ | Postgres |
| MySQL | 🛣️ | MySql |
All contributions are appreciated, 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.
