GlitchedPolygons.DataTransferObject 1.0.3

Prefix Reserved
dotnet add package GlitchedPolygons.DataTransferObject --version 1.0.3
                    
NuGet\Install-Package GlitchedPolygons.DataTransferObject -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GlitchedPolygons.DataTransferObject" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GlitchedPolygons.DataTransferObject" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="GlitchedPolygons.DataTransferObject" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GlitchedPolygons.DataTransferObject --version 1.0.3
                    
#r "nuget: GlitchedPolygons.DataTransferObject, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GlitchedPolygons.DataTransferObject@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GlitchedPolygons.DataTransferObject&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=GlitchedPolygons.DataTransferObject&version=1.0.3
                    
Install as a Cake Tool

DTOs

Love 'em or hate 'em

We all use them (hopefully)

This is a lightweight, zero-dependency library for C# that allows you to define your mapping logic once and use it for both EF Core SQL projections and high-performance in-memory mapping.

The problem

Usually, you have to choose between:

  1. Manual Selects: Efficient SQL, but you duplicate code everywhere.
  2. AutoMapper/Methods: Cleaner code, but often accidentally results in "Select All" queries or expensive runtime compilation.
The solution

This interface here uses C# 11 Static Abstract Members to create a single source of truth for your DTO's base.

  1. Define your DTO
public class UserDto : IDataTransferObject<User, UserDto>
{
    public int Id { get; init; }

    public string? FullName { get; init; }

    // This is used by EF Core for SQL Generation via ".Select(UserDto.MapExpression)"
    public static Expression<Func<User, UserDto>> MapExpression => 
        user => new UserDto 
        { 
            Id = user.Id, 
            FullName = user.FullName
        };
}
  1. Use it in EF Core (SQL)

Pass the expression directly into .Select(). Because it's an Expression, EF Core generates optimized SQL, fetching only the required columns.

IReadOnlyCollection<UserDto> users = 
    await 
        databaseContext
        .Users
        .Select(UserDto.MapExpression)
        .ToListAsync()
        ;
  1. Use it In-Memory (C#)

When you already have an entity in memory, you can use the Map helper.

The library automatically compiles and caches the expression into a high-speed delegate the first time it is used.

User userEntity = GetUserFromCache();

// This uses the cached delegate (no reflection, no re-compilation).
UserDto dto = Map<User>.To<UserDto>(userEntity);

Requirements

  • .NET 10+
  • C# 11+
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 122 4/23/2026
1.0.2 104 4/23/2026
1.0.1 95 4/23/2026
1.0.0 103 4/22/2026