Facet.Extensions 1.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Facet.Extensions --version 1.5.0
                    
NuGet\Install-Package Facet.Extensions -Version 1.5.0
                    
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="Facet.Extensions" Version="1.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Facet.Extensions" Version="1.5.0" />
                    
Directory.Packages.props
<PackageReference Include="Facet.Extensions" />
                    
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 Facet.Extensions --version 1.5.0
                    
#r "nuget: Facet.Extensions, 1.5.0"
                    
#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.
#addin nuget:?package=Facet.Extensions&version=1.5.0
                    
Install Facet.Extensions as a Cake Addin
#tool nuget:?package=Facet.Extensions&version=1.5.0
                    
Install Facet.Extensions as a Cake Tool

This is a new project, any help, feedback and contributions are highy appreciated.

Facet

"One part of a subject, situation, object that has many parts."

Facet is a source generator that instantly scaffolds DTOs, typed LINQ projections, and ViewModels without any runtime overhead.


  • Zero runtime cost: all mapping logic happens at compile time
  • Boilerplate-free: write only your domain and facet definitions
  • Configurable: exclude members, include fields, add custom mapping
  • Queryable: produce Expression<Func<TSource,TTarget>> for EF Core and other LINQ providers

Feature Description
Partial classes & records Generate partial class or record from your types
Exclude members Omit unwanted properties or fields via attribute parameters
Include public fields Opt‑in support for mapping public fields
Custom mapping logic Hook into IFacetMapConfiguration<TSource, TTarget> with static Map()
Constructor & projection Auto-generate ctor and/or Expression<Func<…, …>> for LINQ providers
Records, classes, readonly, init-only Works with all member kinds

Quick Start

1. Install

dotnet add package Facet

2. Create your facet

Define a partial class, attach the Facet attribute and you're done. By default you get:

  • A constructor (TSource source)
  • A static Expression<Func<TSource,TTarget>> Projection
using Facet;

public class Person
{
    public string Name { get; set; }
    public string Email { get; set; }
    public int Age { get; set; }
    public Guid RawId;
}

// Generate class that can be mapped from source model

[Facet(typeof(Person), GenerateConstructor = true)]
public partial class PersonDto { }

// Generate class while adding and removing properties
// You can pass an array of properties to exclude

[Facet(typeof(Person), exclude: nameof(Person.Email)]
public partial class PersonWithNote 
{
    public string Note { get; set; }
}

[Facet(typeof(Person), Kind = FacetKind.Record]
public partial record PersonRecord
{
    // ..
}

The PersonDto will have a constructor that maps the source type properties.

PersonWithNote is generated and will not have the Email property, but will have the Note property.

PersoneRecord is generated as a record

You can map source to target:

var person = new Person { Name = "Tim", Email = "x@x.com", Age = 33, RawId = Guid.NewGuid() };

// 3.1 Constructor mapping
var dto = new PersonDto(person);

Ergonomic mapping helpers (optional)

If you install Facet.Extensions, you get extension methods:

using Facet.Extensions;

// Single-object ctor mapping
var dto = person.ToFacet<Person,PersonDto>();

// In-memory list mapping
var dtos = people.SelectFacets<Person,PersonDto>().ToList();

// Deferred projection
var dtos = dbContext.People
    .SelectFacet<Person,PersonDto>()
    .ToList();

And if you install Facet.EntityFrameworkCore (on .NET 6+):

using Facet.EntityFrameworkCore;

// Async bulk projection
var dtosAsync = await dbContext.People
    .SelectFacet<Person,PersonDto>()
    .ToFacetsAsync(cancellationToken);

// Async first-or-default
var first = await dbContext.People
    .FirstFacetAsync<Person,PersonDto>(cancellationToken);

Advanced mapping

Custom map configuration

Install the package:

dotnet add package Facet.Mapping

Define a mapping config

using Facet;

public class UserMapConfig : IFacetMapConfiguration<User,UserDto>
{
    public static void Map(User src, UserDto dst)
    {
        dst.FullName       = $"{src.FirstName} {src.LastName}";
        dst.RegisteredText = src.Registered.ToString("yyyy-MM-dd");
    }
}

Apply

[Facet(
    typeof(User),
    exclude: new[] { "Password" },
    Configuration = typeof(UserMapConfig))]
public partial class UserDto { public string FullName { get; set; } }
Product 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.7.0 104 5/6/2025
1.6.0 120 4/27/2025
1.5.0 124 4/27/2025