Questions tagged [dapper-fluentmap]

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

Dapper.FluentMap provides a simple API to map your POCO properties to database columns when using Dapper. This avoids the need of specifying column aliases in your queries and keeps your POCO's clean of mapping attributes.

To install the NuGet package, enter the folowing in the package manager console:

PM> Install-Package Dapper.FluentMap

Dapper.FluentMap supports manual mapping and convention based mapping.

A manual map would look like:

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();
    }
}

A typical convention implementation looks like this:

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"));
    }
}

For more info about mapping, configuration and initialization: see the docs.

16 questions
3
votes
0 answers

Dapper Dommel - query join automatic mapping

I'm sorry for my bad english, but here it goes, I am using Dapper with Dapper Dommel to simplify operations like crud, but in Dommel's Github says that it supports Join operations too, so I'm trying to implement it on my code, so far I managed to…
3
votes
2 answers

How to use dapper.fluentmap in Dapper?

Does anyone know or have link in how to use https://github.com/henkmollema/Dapper-FluentMap in my Dapper CRUD?. Right now I am using Dapper.Contrib but we are trying to implement Clean architecture which we remove the Dapper.Contrib in our…
user3928241
  • 135
  • 2
  • 10
2
votes
1 answer

How to map a unidirectional many-to-one relationship?

I have an Item entity: public class Item { public long Id { get; set; } public string Name { get; set; } public string Skuid { get; set; } public double Price { get; set; } public double Amount { get; set; } } And an Order…
2
votes
2 answers

How can you do one to many mapping with FluentMap?

I've just started using FluentMap and I'm looking to map the same column to 2 properties, as they need the same value. Here's my map: internal class DefaultsMap : EntityMap { internal DefaultsMap() { Map(d =>…
sr28
  • 4,728
  • 5
  • 36
  • 67
2
votes
1 answer

How can you initialize a map in a DAL project?

I've got a simple solution structure of API project, DAL project (Class Library), shared Models project. Inside the DAL project I've created a custom map for one of my POCO's: internal class AssumptionsMap : EntityMap { internal…
sr28
  • 4,728
  • 5
  • 36
  • 67
2
votes
3 answers

Dapper complex mapping Dapper.Extensions Dapper.FluentMap

I have a bit of a problem with my code and getting dapper to play nicely with it. When I say my code it was inherited, so this is not my design. I am trying to replace Entity Framework as the calls to the database are less than efficient so I wanted…
jimplode
  • 3,474
  • 3
  • 24
  • 42
1
vote
0 answers

Dapper.FluentMap bug for nullable decimal

I was looking to find a simple way to map a class property to a table column and I found Dapper fluent map which I thought was going to be a great alternative to the considerable boilerplate code that one would need to write simply to map a property…
Anand
  • 1,387
  • 2
  • 26
  • 48
1
vote
1 answer

How to parse a postgresql UUID into a C# string using Dapper FluentMap?

I have a function that is returning (among other things) a UUID. I am using FluentMap to handle some return columns that include spaces, but the column in question (invoice_id) doesn't have that issue. An abbreviated version of the db query: CREATE…
Joe M
  • 3,060
  • 3
  • 40
  • 63
1
vote
1 answer

Micro ORM Dapper Could not find the key property for type

I am new to Micro-ORM i am using dapper fluent mapping and dommel I try to insert/add entries but I encounter this error "Could not find the key property for type" here is my Code using (IDbConnection con = new MySqlConnection(cnxStr)) …
jake talledo
  • 610
  • 11
  • 24
1
vote
1 answer

using dapper to insert with stored procedure ( maybe tvp )

I have a model PersonalInfo like so: public string FirstName { get; set;} public string LastName { get; set;} public string Email { get; set; } public IEnumerable Addresses{ get; set; } And my Addresses model include something…
NoviceDeveloper
  • 1,270
  • 3
  • 15
  • 41
0
votes
1 answer

Map Dapper query multiple to strongly typed object?

I have the following sproc: CREATE PROCEDURE [dbo].[dapper_test_sproc] AS BEGIN SET NOCOUNT ON ; DECLARE @Status INT = 1 DECLARE @Msg VARCHAR(256) = 'Hello World' DECLARE @StatusLines TABLE ( …
Victorio Berra
  • 2,760
  • 2
  • 28
  • 53
0
votes
1 answer

How to use Dapper with Dommel and FluentMap to Insert a record into a table that doesn't have an Key?

I'm creating a service in my API that uses Dapper with Dommel and FluentMap. The database is Microsoft SQL Server. I have an endpoint that needs to insert a record into an table that hasn't a key. The table is described like in this entity…
tfidelis
  • 443
  • 8
  • 16
0
votes
2 answers

How do I use Dapper.Contrib with FluentMap to update an entity with an identity column?

I have a class called Business, which has a property Id that is a identity field in MS SQL Server database. When I do an INSERT, it works properly. If I do the following: _db.Update(business); I get an error: invalid column name 'id" the column in…
Maccurt
  • 12,655
  • 7
  • 32
  • 43
0
votes
1 answer

Dapper Dommel - Usinng Like-queries issue

I'm trying to use Like-queries as shown in Dommel documetation: using (var con = new SqlConnection()) { var products = con.Select(p => p.Name == "Awesome bike"); var products = con.Select(p => p.Created < new DateTime(2014,…
Giancarlo Melis
  • 697
  • 4
  • 17
0
votes
1 answer

Dapper fluent map doesn't change name of my column

I have installed Dapper extension + fluentmapper for customing my own columns. I have followed examples but nothing, the name of my column doesn't change. I'm doing repository. Models : public class AppareilsReparations { public string…
Deos
  • 55
  • 2
  • 9
1
2