A hybrid .NET ORM library for MySQL (using MySql.Data).
$ dotnet add package AmpScm.RepoDb.MySqlRepoDB is an open-source .NET ORM library that bridges the gaps of micro-ORMs and full-ORMs. It helps you simplify the switch-over of when to use the BASIC and ADVANCE operations during the development.
At the Package Manager Console, write the command below.
> Install-Package AmpScm.RepoDb.MySqlOr, visit our installation page for more information.
First, RepoDB must be configured and MySql support loaded.
GlobalConfiguration.Setup().UseMySql();Note: The call must be done once.
After the bootstrap initialization, any library operation can then be called.
Or, visit the official get-started page for MySQL.
using (var connection = new MySqlConnection(ConnectionString))
{
var customer = connection.Query<Customer>(c => c.Id == 10045);
}var customer = new Customer
{
FirstName = "John",
LastName = "Doe",
IsActive = true
};
using (var connection = new MySqlConnection(ConnectionString))
{
var id = connection.Insert<Customer>(customer);
}using (var connection = new MySqlConnection(ConnectionString))
{
var customer = connection.Query<Customer>(10045);
customer.FirstName = "John";
customer.LastUpdatedUtc = DateTime.UtcNow;
var affectedRows = connection.Update<Customer>(customer);
}using (var connection = new MySqlConnection(ConnectionString))
{
var customer = connection.Query<Customer>(10045);
var deletedCount = connection.Delete<Customer>(customer);
}