All Projects → henkmollema → Dommel

henkmollema / Dommel

Licence: mit
CRUD operations with Dapper made simple.

Projects that are alternatives of or similar to Dommel

dapper-repositories
CRUD for Dapper
Stars: ✭ 523 (+79.73%)
Mutual labels:  crud, query-builder, dapper
Microorm.dapper.repositories
CRUD for Dapper
Stars: ✭ 424 (+45.7%)
Mutual labels:  query-builder, crud, dapper
Evolutility Server Node
Model-driven REST or GraphQL backend for CRUD and more, written in Javascript, using Node.js, Express, and PostgreSQL.
Stars: ✭ 84 (-71.13%)
Mutual labels:  query-builder, crud
flepper
Flepper is a library to aid in database interaction. 🐸
Stars: ✭ 60 (-79.38%)
Mutual labels:  query-builder, dapper
Vanilla Rtb
Real Time Bidding (RTB) - Demand Side Platform framework
Stars: ✭ 257 (-11.68%)
Mutual labels:  crud
ucast
Conditions query translator for everything
Stars: ✭ 76 (-73.88%)
Mutual labels:  query-builder
FISCO-BCOS
FISCO BCOS是由微众牵头的金链盟主导研发、对外开源、安全可控的企业级金融区块链底层技术平台。 单链配置下,性能TPS可达万级。提供群组架构、并行计算、分布式存储、可插拔的共识机制、隐私保护算法、支持全链路国密算法等诸多特性。 经过多个机构、多个应用,长时间在生产环境中的实践检验,具备金融级的高性能、高可用性及高安全性。FISCO BCOS is a secure and reliable financial-grade open-source blockchain platform. The platform provides rich features including group architecture, cross-chain communication protoc…
Stars: ✭ 1,603 (+450.86%)
Mutual labels:  crud
Ad-Hoc-Report-Builder-.net-mvc
Open Source Reporting tool for .NET6/.NET Core/.NET Framework that you can embed in your application and generate dashboards and ad hoc reports
Stars: ✭ 43 (-85.22%)
Mutual labels:  query-builder
Skywalking
APM, Application Performance Monitoring System
Stars: ✭ 18,341 (+6202.75%)
Mutual labels:  dapper
Dapper Plus
Dapper Plus - High-Efficient Bulk Actions (Insert, Update, Delete, and Merge) for .NET
Stars: ✭ 265 (-8.93%)
Mutual labels:  dapper
skywalking-rust
Apache SkyWalking Rust Agent
Stars: ✭ 25 (-91.41%)
Mutual labels:  dapper
helppo
Instant admin UI for your database
Stars: ✭ 14 (-95.19%)
Mutual labels:  crud
Postgui
A React web application to query and share any PostgreSQL database.
Stars: ✭ 260 (-10.65%)
Mutual labels:  query-builder
CRUDReactNativeSQLite
CRUD de app em React Native utilizando armazenamento local com SQLite
Stars: ✭ 16 (-94.5%)
Mutual labels:  crud
Redux Orm
A small, simple and immutable ORM to manage relational data in your Redux store.
Stars: ✭ 2,922 (+904.12%)
Mutual labels:  crud
diesel
No description or website provided.
Stars: ✭ 30 (-89.69%)
Mutual labels:  query-builder
angular-forum
Forum application built with Angular
Stars: ✭ 52 (-82.13%)
Mutual labels:  crud
Eloquent Builder
Provides an advanced filter for Laravel or Lumen model.
Stars: ✭ 264 (-9.28%)
Mutual labels:  query-builder
crudify
A Laravel 8 CRUD package for rapid scaffolding and development.
Stars: ✭ 17 (-94.16%)
Mutual labels:  crud
ux
Laravel UI, Auth, & CRUD scaffolding package using Bootstrap & Livewire.
Stars: ✭ 34 (-88.32%)
Mutual labels:  crud

Dommel

CRUD operations with Dapper made simple.

Windows Linux NuGet MyGet Test Coverage
AppVeyor Travis NuGet MyGet Pre Release codecov

Dommel provides a convenient API for CRUD operations using extension methods on the IDbConnection interface. The SQL queries are generated based on your POCO entities. Dommel also supports LINQ expressions which are being translated to SQL expressions. Dapper is used for query execution and object mapping.

There are several extensibility points available to change the behavior of resolving table names, column names, the key property and POCO properties. See Extensibility for more details.

Download

Dommel is available on NuGet:

Using the .NET Core CLI:

dotnet add package Dommel

Using the NuGet Package Manager:

PM> Install-Package Dommel

API

Retrieving entities by ID

using (var con = new SqlConnection())
{
   var product = con.Get<Product>(1);
}

Retrieving all entities in a table

using (var con = new SqlConnection())
{
   var products = con.GetAll<Product>().ToList();
}

Selecting entities using a predicate

Dommel allows you to specify a predicate which is being translated into a SQL expression. The arguments in the lambda expression are added as parameters to the command.

using (var con = new SqlConnection())
{
   var products = con.Select<Product>(p => p.Name == "Awesome bike");

   var products = con.Select<Product>(p => p.Created < new DateTime(2014, 12, 31) && p.InStock > 5);
}

Like-queries

It is possible to generate LIKE-queries using Contains(), StartsWith() or EndsWith() on string properties:

using (var con = new SqlConnection())
{
   var products = con.Select<Product>(p => p.Name.Contains("bike"));
   var products = con.Select<Product>(p => p.Name.StartsWith("bike"));
   var products = con.Select<Product>(p => p.Name.EndsWith("bike"));
}

Inserting entities

using (var con = new SqlConnection())
{
   var product = new Product { Name = "Awesome bike", InStock = 4 };
   int id = con.Insert(product);
}

Updating entities

using (var con = new SqlConnection())
{
   var product = con.Get<Product>(1);
   product.LastUpdate = DateTime.UtcNow;
   con.Update(product);
}

Removing entities

using (var con = new SqlConnection())
{
   var product = con.Get<Product>(1);
   con.Delete(product);
}

Multi mapping

One-to-one relations

Dommel is able to generate join-queries based on the specified multi mapping function. Consider the following POCO's:

public class Product
{
    public int Id { get; set; }

    public string Name { get; set; }

    // Maps to the foreign key column
    public int CategoryId { get; set; }

    // The navigation property
    public Category Category { get; set; }
}


public class Category
{
    public int Id { get; set; }

    public string Name { get; set; }
}

The Product with its associated Category can be queried toegether using the Get<T1, T2, ..., TResult>() method:

var product = product.Get<Product, Category, Product>(1, (product, category) =>
{
    product.Category = category;
    return product;
});

Foreign key columns

CategoryId is automatically used as foreign key between Product and Category. This follows a simple convention: joining table name + Id (Category + Id). You can override this behavior by using the [ForeignKey("ForeignKeyColumnName")] attribute or by implementing your own IForeignKeyPropertyResolver.

One-to-many relations

One-to-many relationships work in a similar way, expect that the foreign key is defined on the joined type rather than the source type. For example:

public class Order
{
    public int Id { get; set; }

    // The navigation property
    public ICollection<OrderLine> OrderLines { get; set; } = new List<OrderLine>();
}

public class OrderLine
{
    public int Id { get; set; }

    // The foreign key column to the Order table
    public int OrderId { get; set; }

    public string Description { get; set; }
}

The Order with its child OrderLine's can be queried toegether using the Get<T1, T2, ..., TResult>() method:

var product = product.Get<Order, OrderLine, Order>(1, (order, line) =>
{
    // Naive mapping example, in reality it requires more gymnastics
    order.OrderLines.Add(line);
    return order;
});

Automatic multi mapping

Note: this is an experimental feature.

Dommel is able to create simple join-expressions for retrieving parent-child entities. One-to-one and one-to-many relations are supported. It works the samy way as regular mapping, except there is no need to specify a function which performs the mapping of the objects. Using the same POCO's as the previous examples:

Retrieving a Product and its associated Category:

var product = product.Get<Product, Category, Product>(1);

Retrieving one Order and with its child OrderLine's:

var product = product.Get<Order, OrderLine, Order>(1);

Entity equality

When joining with two or more tables with a one-to-many relationship, you are required to override Equals(object obj) method or implement the IEquatable<T> interface on your POCO's so Dommel can determine whether an entity is already added to the collection. For example:

public class OrderLine : IEquatable<OrderLine>
{
    public int Id { get; set; }

    public int OrderId { get; set; }

    public string Description { get; set; }

    public bool Equals(OrderLine other) => Id == other.Id;
}

Async

All Dommel methods have an async counterparts, such as as GetAsync, GetAllAsync, SelectAsync, InsertAsync, UpdateAsync, DeleteAsync, etc.

Query builders

Dommel supports building specialized queries for a certain RDBMS. By default, query builders for the following RDMBS are included: SQL Server, SQL Server CE, SQLite, MySQL and Postgres. The query builder to be used is determined by the connection type. To add or overwrite an existing query builder, use the AddSqlBuilder() method:

DommelMapper.AddSqlBuilder(typeof(SqlConnection), new CustomSqlBuilder());

Extensibility

ITableNameResolver

Implement this interface if you want to customize the resolving of table names when building SQL queries.

public class CustomTableNameResolver : DommelMapper.ITableNameResolver
{
    public string ResolveTableName(Type type)
    {
        // Every table has prefix 'tbl'.
        return $"tbl{type.Name}";
    }
}

Use the SetTableNameResolver() method to register the custom implementation:

DommelMapper.SetTableNameResolver(new CustomTableNameResolver());

IKeyPropertyResolver

Implement this interface if you want to customize the resolving of the key property of an entity. By default, Dommel will search for a property with the [Key] attribute, or a column with the name 'Id'.

If you, for example, have the naming convention of {TypeName}Id for key properties, you would implement the IKeyPropertyResolver like this:

public class CustomKeyPropertyResolver : DommelMapper.IKeyPropertyResolver
{
    public PropertyInfo ResolveKeyProperty(Type type)
    {
        return type.GetProperties().Single(p => p.Name == $"{type.Name}Id");
    }
}

Use the SetKeyPropertyResolver() method to register the custom implementation:

DommelMapper.SetKeyPropertyResolver(new CustomKeyPropertyResolver());

IForeignKeyPropertyResolver

Implement this interface if you want to customize the resolving of the foreign key property from one entity to another. By default Dommel will search for a property of {TypeName}Id or the column name specified using the [ForeignKey] attribute.

This is a rather advanced interface. Providing your own implementation requires quite some knowledge of the way Dommel handles foreign key relationships. Consider subclassing DefaultForeignKeyPropertyResolver and override ResolveForeignKeyProperty().

Use the SetForeignKeyPropertyResolver() method to register the custom implementation:

DommelMapper.SetForeignKeyPropertyResolver(new CustomForeignKeyPropertyResolver());

IColumnNameResolver

Implement this interface if you want to customize the resolving of column names for when building SQL queries. This is useful when your naming conventions for database columns are different than your POCO properties.

public class CustomColumnNameResolver : DommelMapper.IColumnNameResolver
{
    public string ResolveColumnName(PropertyInfo propertyInfo)
    {
        // Every column has prefix 'fld' and is uppercase.
        return $"fld{propertyInfo.Name.ToUpper()}";
    }
}

Use the SetColumnNameResolver() method to register the custom implementation:

DommelMapper.SetColumnNameResolver(new CustomColumnNameResolver());

The Dapper.FluentMap.Dommel extension implements these interfaces using the configured mapping of Dapper.FluentMap. Also see: Dapper.FluentMap.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].