Skip to content

Latest commit

 

History

History
47 lines (31 loc) · 1.52 KB

immutable-objects.md

File metadata and controls

47 lines (31 loc) · 1.52 KB
title Immutable Objects
description Bind constructor parameters to mapped columns for immutable models.
Home/Advanced Mapping/Immutable Objects

Required package: Dapper.FluentMap

Problem solved

Bind constructor parameters to mapped columns for immutable models.

When to use it

Use this capability when the column shape and .NET model should remain separated by explicit, reviewable configuration.

Example

public sealed class CustomerMap : EntityMap<Customer>
{
    public CustomerMap()
    {
        Map(x => x.Id).ToColumn("customer_id");
        Map(x => x.Name).ToColumn("customer_name");
    }
}

var customer = connection.QueryMappedSingle<Customer>(sql);

How it works

FluentMap registers typed metadata and applies it through the matching materialization path. SQL, connections, parameters, and lifecycle remain responsibilities of the application and Dapper.

Constraints

:::caution Initialize before concurrent queries and treat the effective configuration as read-only afterward. :::

Related references