Language: EN

repodb-un-micro-orm-hibrido-para-net

RepoDb, a hybrid micro ORM for .NET applications

RepoDb is an Open Source ORM for .NET, which comes to fill the gap between micro ORMs like Dapper, and full ORMs like Entity Framework.

It is designed to be fast in execution and efficient in memory usage, achieving similar or even superior results to the popular Dapper library.

At the same time, RepoDb makes an effort to maintain ease of use. The provided functions are included as extension methods for IDbConnection, similar to what Dapper does.

On the other hand, in addition to performing queries with Raw Sql, it maintains high-level features similar to those found in Entity Framework, allowing its use with a simple syntax through lambda functions and anonymous types.

The library is compatible with major databases such as SQL Server, SQLite, MySQL/MariaDb, and PostgreSQL. It also incorporates numerous additional features such as cache, tracing, and bulk operations.

RepoDb is available to be added as a Nuget package, and is compatible with .NET Standard 2.0, so it is available on Windows, Linux (Mono), and Android (Xamarin).

As we mentioned at the beginning, RepoDb is Open Source. The code and documentation are available on the project page https://github.com/mikependon/RepoDb.

Using RepoDb

Let’s see some simple examples of using RepoDb. Before we can use RepoDB, we must initialize the library, according to the data provider we are using. For example, for the case of Sql Server we would do.

RepoDb.SqlServerBootstrap.Initialize();

This statement must be executed only once, so we normally call it from the AppBoostrapper of the application, in the constructor of the services layer, or in our dependency resolution system.

CRUD Operations

Once RepoDb is initialized, basic CRUD operations are as simple as.

Create an entry


var person = new Person
{
    Name = "John Doe",
    Age = 54,
    CreatedDateUtc = DateTime.UtcNow
};
using (var connection = new SqlConnection(ConnectionString))
{
    var id = connection.Insert(person);
}

Read an entry


using (var connection = new SqlConnection(ConnectionString))
{
    var person = connection.Query<Person>(e => e.Id == 10045);
    /* Do the stuffs for person here */
}

Update an entry


var person = new Person
{
    Id = 1,
    Name = "James Doe",
    Age = 55,
    DateInsertedUtc = DateTime.UtcNow
};
using (var connection = new SqlConnection(ConnectionString))
{
    var updatedRows = connection.Update<Person>(person);
}

Delete an entry

using (var connection = new SqlConnection(ConnectionString))
{
    var deletedRows = connection.Delete<Person>(10045);
}

Of course, these are only the simplest cases we can perform with RepoDb. For more information, check the project’s website, which provides abundant documentation on the library’s functionalities and its use.