ArchPillar.Extensions.Mapper
1.5.0-preview9
dotnet add package ArchPillar.Extensions.Mapper --version 1.5.0-preview9
NuGet\Install-Package ArchPillar.Extensions.Mapper -Version 1.5.0-preview9
<PackageReference Include="ArchPillar.Extensions.Mapper" Version="1.5.0-preview9" />
<PackageVersion Include="ArchPillar.Extensions.Mapper" Version="1.5.0-preview9" />
<PackageReference Include="ArchPillar.Extensions.Mapper" />
paket add ArchPillar.Extensions.Mapper --version 1.5.0-preview9
#r "nuget: ArchPillar.Extensions.Mapper, 1.5.0-preview9"
#:package ArchPillar.Extensions.Mapper@1.5.0-preview9
#addin nuget:?package=ArchPillar.Extensions.Mapper&version=1.5.0-preview9&prerelease
#tool nuget:?package=ArchPillar.Extensions.Mapper&version=1.5.0-preview9&prerelease
ArchPillar.Extensions.Mapper
A .NET library for explicit object-to-object DTO mapping and LINQ/EF Core expression projection. One mapper definition drives both in-memory object mapping and IQueryable projection — and every mapper is a named C# property, so Go to Definition and Find All References work the same as any other code.
Why?
AutoMapper is everywhere, and for good reason — it solves a real problem. But its convention-based, implicit nature creates a different one: when a mapping breaks, you cannot trace it. A renamed property silently stops mapping, a misconfigured profile produces wrong data instead of a compile error, and "Find All References" on a DTO property turns up nothing because the mapping is invisible.
ArchPillar.Extensions.Mapper takes the opposite approach:
- Every mapping is explicit — no convention-based auto-discovery, no magic.
- Every mapper is a named C# property — fully navigable by IDE tooling.
- Unmapped properties are build-time errors — silence is not acceptance.
- One definition, two modes — the same mapper produces both compiled delegates and LINQ expression trees, with no client-side evaluation and no N+1.
The core library is provider-agnostic and depends only on BCL types. An opt-in companion package, ArchPillar.Extensions.Mapper.EntityFrameworkCore, adds EF Core query-time support — see EF Core integration below.
Quick Start
// 1. Define your mapper context (like EF Core's DbContext)
public class AppMappers : MapperContext
{
public Variable<int> CurrentUserId { get; } = CreateVariable<int>();
public Mapper<OrderLine, OrderLineDto> OrderLine { get; }
public Mapper<Order, OrderDto> Order { get; }
public AppMappers()
{
OrderLine = CreateMapper<OrderLine, OrderLineDto>(src => new OrderLineDto
{
ProductName = src.Product.Name,
Quantity = src.Quantity,
UnitPrice = src.UnitPrice,
});
Order = CreateMapper<Order, OrderDto>(src => new OrderDto
{
Id = src.Id,
Status = src.Status.ToString(),
IsOwner = src.OwnerId == CurrentUserId,
Lines = src.Lines.Project(OrderLine).ToList(),
})
.Optional(dest => dest.CustomerName, src => src.Customer.Name);
EagerBuildAll();
}
}
// 2. Use it — in memory
var mappers = new AppMappers();
OrderDto dto = mappers.Order.Map(order);
// 3. Use it — as IQueryable projection (single SQL query, no N+1)
var dtos = await dbContext.Orders
.Where(o => o.IsActive)
.Project(mappers.Order, o => o
.Include(m => m.CustomerName)
.Set(mappers.CurrentUserId, currentUser.Id))
.ToListAsync();
Both paths use the same definition. The LINQ provider sees a plain expression tree — no delegate calls, no client-side evaluation.
Mapping styles
Declare properties with a member-init expression, a fluent .Map() chain, or a mix of both. Coverage validation ensures every destination property is mapped, optional, or ignored, throwing at build time if one is missed.
Order = CreateMapper<Order, OrderDto>(src => new OrderDto
{
Id = src.Id,
PlacedAt = src.CreatedAt,
Lines = src.Lines.Project(OrderLine).ToList(), // nested mapper, inlined
})
.Map(dest => dest.Status, src => src.Status.ToString())
.Optional(dest => dest.CustomerName, src => src.Customer.Name); // opt-in
Nested mapper calls (Map(src.X) for single objects, src.X.Project(mapper) for collections) are inlined into the parent expression at build time. Enum-to-enum mapping (EnumMapper<,>, SymmetricEnumMapper<,>), shallow cloning (CreateCloneMapper<T>()), destination-hierarchy reuse (Inherit(...).For<T>()), in-place updates (MapTo), and expression transformers are all supported.
Runtime variables and optionals
Variable<T> properties are typed expression placeholders bound at the call site — no magic strings. Optional properties are requested per call via typed Include() or string paths, mirroring EF Core's Include / ThenInclude:
mappers.Order.Map(order, o => o.Set(mappers.CurrentUserId, userId));
query.Project(mappers.Order, o => o
.Include(m => m.CustomerName)
.Include("Lines.SupplierName"));
EF Core integration
Project(mapper) and ToExpression() emit plain expression trees that EF Core translates directly — no extra package needed for whole-row projection. The opt-in companion package ArchPillar.Extensions.Mapper.EntityFrameworkCore adds query-time support, registered once on the DbContextOptionsBuilder:
builder.Services.AddDbContext<AppDbContext>(options =>
options
.UseNpgsql(connectionString)
.UseArchPillarMapper());
It inlines direct Map() / Project() calls made inside a hand-written Select, and translates enum mapper calls to a flat SQL CASE. The core library stays provider-agnostic and dependency-free.
Documentation
Full documentation, features, and examples are in the GitHub repository.
License
MIT — see the bundled LICENSE file.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ArchPillar.Extensions.Mapper:
| Package | Downloads |
|---|---|
|
ArchPillar.Extensions.Mapper.EntityFrameworkCore
EF Core integration for ArchPillar.Extensions.Mapper. Translates EnumMapper.Map() calls into flat SQL CASE expressions and inlines direct Mapper.Map()/Project() calls inside hand-written query projections for full server-side translation. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.5.0-preview9 | 147 | 8/3/2026 |
| 1.5.0-preview8 | 147 | 7/31/2026 |
| 1.5.0-preview7 | 138 | 7/30/2026 |
| 1.5.0-preview6 | 144 | 7/29/2026 |
| 1.5.0-preview5 | 140 | 7/26/2026 |
| 1.5.0-preview4 | 141 | 7/25/2026 |
| 1.5.0-preview3 | 160 | 6/17/2026 |
| 1.5.0-preview2 | 163 | 6/17/2026 |
| 1.5.0-preview15 | 129 | 8/21/2026 |
| 1.5.0-preview14 | 134 | 8/17/2026 |
| 1.5.0-preview13 | 133 | 8/11/2026 |
| 1.5.0-preview12 | 131 | 8/10/2026 |
| 1.5.0-preview11 | 137 | 8/10/2026 |
| 1.5.0-preview10 | 132 | 8/6/2026 |
| 1.5.0-preview1 | 152 | 6/16/2026 |
| 1.4.4 | 197 | 6/15/2026 |
| 1.4.3 | 166 | 6/14/2026 |
| 1.4.2 | 151 | 6/14/2026 |
| 1.4.1 | 160 | 6/14/2026 |
| 1.4.0 | 163 | 6/13/2026 |