All Projects → henkmollema → Dapper Fluentmap

henkmollema / Dapper Fluentmap

Licence: mit
Provides a simple API to fluently map POCO properties to database columns when using Dapper.

Labels

Projects that are alternatives of or similar to Dapper Fluentmap

dapper-repositories
CRUD for Dapper
Stars: ✭ 523 (+58.97%)
Mutual labels:  dapper
skywalking-nodejs
The NodeJS agent for Apache SkyWalking
Stars: ✭ 81 (-75.38%)
Mutual labels:  dapper
skywalking-rust
Apache SkyWalking Rust Agent
Stars: ✭ 25 (-92.4%)
Mutual labels:  dapper
GraphQL.RepoDB
A set of extensions for working with HotChocolate GraphQL and Database access with micro-orms such as RepoDb (or Dapper). This extension pack provides access to key elements such as Selections/Projections, Sort arguments, & Paging arguments in a significantly simplified facade so this logic can be leveraged in the Serivces/Repositories that enca…
Stars: ✭ 25 (-92.4%)
Mutual labels:  dapper
aspnet-mvc5-starter-template
Asp.Net MVC 5 Starter Kit is a S.O.L.I.D, clean and globalized template with all the necessary boilerplate, ready to go.
Stars: ✭ 39 (-88.15%)
Mutual labels:  dapper
Ark.Tools
Ark set of helper libraries
Stars: ✭ 20 (-93.92%)
Mutual labels:  dapper
skywalking-client-js
Client-side JavaScript exception and tracing library for Apache SkyWalking APM.
Stars: ✭ 171 (-48.02%)
Mutual labels:  dapper
Dommel
CRUD operations with Dapper made simple.
Stars: ✭ 291 (-11.55%)
Mutual labels:  dapper
react-redux-aspnet-core-webapi
No description or website provided.
Stars: ✭ 34 (-89.67%)
Mutual labels:  dapper
ddd-net-ef-core
Self study: DDD, .net core, entity framework core
Stars: ✭ 41 (-87.54%)
Mutual labels:  dapper
CodexMicroORM
An alternative to ORM's such as Entity Framework, offers light-weight database mapping to your existing CLR objects. Visit "Design Goals" on GitHub to see more rationale and guidance.
Stars: ✭ 32 (-90.27%)
Mutual labels:  dapper
litelib
A cool little wrapper in Entity Framework style for SQLite based on Dapper
Stars: ✭ 63 (-80.85%)
Mutual labels:  dapper
RepositoryHelpers
📦 Extensions for HttpClient and Custom Repository based on dapper
Stars: ✭ 22 (-93.31%)
Mutual labels:  dapper
money
Dapper Style Distributed Tracing Instrumentation Libraries
Stars: ✭ 65 (-80.24%)
Mutual labels:  dapper
Dapper Plus
Dapper Plus - High-Efficient Bulk Actions (Insert, Update, Delete, and Merge) for .NET
Stars: ✭ 265 (-19.45%)
Mutual labels:  dapper
SQLBuilder.Core
.NET Standard 2.1、.NET 5、.NET 6 版本SQLBuilder,Expression表达式转换为SQL语句,支持SqlServer、MySql、Oracle、Sqlite、PostgreSql;基于Dapper实现了不同数据库对应的数据仓储Repository;
Stars: ✭ 85 (-74.16%)
Mutual labels:  dapper
skywalking-kong
Kong agent for Apache SkyWalking
Stars: ✭ 17 (-94.83%)
Mutual labels:  dapper
Jimu
.netcore micro service framework
Stars: ✭ 315 (-4.26%)
Mutual labels:  dapper
Skywalking
APM, Application Performance Monitoring System
Stars: ✭ 18,341 (+5474.77%)
Mutual labels:  dapper
fsharp-dapper
The wrapper above the 'Dapper' library allows you to write more familiar code in the F # language. It also contains a functional for more simple work with temporary tables
Stars: ✭ 72 (-78.12%)
Mutual labels:  dapper

Dapper.FluentMap

Provides a simple API to fluently map POCO properties to database columns when using Dapper.


Windows Linux/OSX NuGet
Windows Build status Linux Build Status NuGet Version

Introduction

This Dapper extension allows you to fluently configure the mapping between POCO properties and database columns. This keeps your POCO's clean of mapping attributes. The functionality is similar to Entity Framework Fluent API. If you have any questions, suggestions or bugs, please don't hesitate to contact me or create an issue.


Download

Download Dapper.FluentMap on NuGet


Usage

Manual mapping

You can map property names manually using the EntityMap<TEntity> class. When creating a derived class, the constructor gives you access to the Map method, allowing you to specify to which database column name a certain property of TEntity should map to.

public class ProductMap : EntityMap<Product>
{
    public ProductMap()
    {
        // Map property 'Name' to column 'strName'.
        Map(p => p.Name)
            .ToColumn("strName");

        // Ignore the 'LastModified' property when mapping.
        Map(p => p.LastModified)
            .Ignore();
    }
}

Column names are mapped case sensitive by default. You can change this by specifying the caseSensitive parameter in the ToColumn() method: Map(p => p.Name).ToColumn("strName", caseSensitive: false).

Initialization:

FluentMapper.Initialize(config =>
    {
       config.AddMap(new ProductMap());
    });

Convention based mapping

When you have a lot of entity types, creating manual mapping classes can become plumbing. If your column names adhere to some kind of naming convention, you might be better off by configuring a mapping convention.

You can create a convention by creating a class which derives from the Convention class. In the contructor you can configure the property conventions:

public class TypePrefixConvention : Convention
{
    public TypePrefixConvention()
    {
        // Map all properties of type int and with the name 'id' to column 'autID'.
        Properties<int>()
            .Where(c => c.Name.ToLower() == "id")
            .Configure(c => c.HasColumnName("autID"));

        // Prefix all properties of type string with 'str' when mapping to column names.
        Properties<string>()
            .Configure(c => c.HasPrefix("str"));

        // Prefix all properties of type int with 'int' when mapping to column names.
        Properties<int>()
            .Configure(c => c.HasPrefix("int"));
    }
}

When initializing Dapper.FluentMap with conventions, the entities on which a convention applies must be configured. You can choose to either configure the entities explicitly or use assembly scanning.

FluentMapper.Initialize(config =>
    {
        // Configure entities explicitly.
        config.AddConvention<TypePrefixConvention>()
              .ForEntity<Product>()
              .ForEntity<Order>;

        // Configure all entities in a certain assembly with an optional namespaces filter.
        config.AddConvention<TypePrefixConvention>()
              .ForEntitiesInAssembly(typeof(Product).Assembly, "App.Domain.Model");

        // Configure all entities in the current assembly with an optional namespaces filter.
        config.AddConvention<TypePrefixConvention>()
              .ForEntitiesInCurrentAssembly("App.Domain.Model.Catalog", "App.Domain.Model.Order");
    });
Transformations

The convention API allows you to configure transformation of property names to database column names. An implementation would look like this:

public class PropertyTransformConvention : Convention
{
    public PropertyTransformConvention()
    {
        Properties()
            .Configure(c => c.Transform(s => Regex.Replace(input: s, pattern: "([A-Z])([A-Z][a-z])|([a-z0-9])([A-Z])", replacement: "$1$3_$2$4")));
    }
}

This configuration will map camel case property names to underscore seperated database column names (UrlOptimizedName -> Url_Optimized_Name).


Dommel

Dommel contains a set of extensions methods providing easy CRUD operations using Dapper. One of the goals was to provide extension points for resolving table and column names. Dapper.FluentMap.Dommel implements certain interfaces of Dommel and uses the configured mapping. It also provides more mapping functionality.

PM> Install-Package Dapper.FluentMap.Dommel

Usage

DommelEntityMap<TEntity>

This class derives from EntityMap<TEntity> and allows you to map an entity to a database table using the ToTable() method:

public class ProductMap : DommelEntityMap<TEntity>
{
    public ProductMap()
    {
        ToTable("tblProduct");

        // ...
    }
}
DommelPropertyMap<TEntity>

This class derives PropertyMap<TEntity> and allows you to specify the key property of an entity using the IsKey method:

public class ProductMap : DommelEntityMap<TEntity>
{
    public ProductMap()
    {
        Map(p => p.Id).IsKey();
    }
}

You can configure Dapper.FluentMap.Dommel in the FluentMapper.Initialize() method:

FluentMapper.Initialize(config =>
    {
        config.AddMap(new ProductMap());
        config.ForDommel();
    });
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].