Facet.Extensions 1.6.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Facet.Extensions --version 1.6.0
                    
NuGet\Install-Package Facet.Extensions -Version 1.6.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.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Facet.Extensions" Version="1.6.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.6.0
                    
#r "nuget: Facet.Extensions, 1.6.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.6.0
                    
Install Facet.Extensions as a Cake Addin
#tool nuget:?package=Facet.Extensions&version=1.6.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 C# source generator that lets you define lightweight projections (DTOs, API models, etc.) directly from your domain models — without writing boilerplate.

It generates partial classes or records with constructors, optional LINQ projections, and even supports custom mappings — all at compile time, with zero runtime cost.


  • ✅ Generate classes or records from existing types
  • ✅ Exclude fields/properties you don't want (basically create a Facetted view of your model))
  • ✅ Include public fields (optional)
  • ✅ Auto-generate constructors for fast mapping
  • ✅ LINQ projection expressions (Expression<Func<TSource,TTarget>>)
  • ✅ Custom mapping via IFacetMapConfiguration
  • ✅ Use in EF Core queries by using Facet.Extensions

Quick Start

1. Install

dotnet add package Facet

2. Define facet

using Facet;

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

// Generate a DTO that excludes Email
[Facet(typeof(Person), exclude: nameof(Person.Email))]
public partial class PersonDto;

This generates a PersonDto with only Name and Age, and a constructor that copies values.

3. Use your generated facets

var person = new Person { Name = "Alice", Email = "a@b.com", Age = 30 };
var dto = new PersonDto(person);

LINQ projection support:

var query = dbContext.People
    .Select(PersonDto.Projection)
    .ToList();

Advanced scenarios

Records

[Facet(typeof(Person), Kind = FacetKind.Record)]
public partial record PersonRecord;
`

Custom mapping

Eg. you need to compile extra fields

public class UserMapConfig : IFacetMapConfiguration<User, UserDto>
{
    public static void Map(User source, UserDto target)
    {
        target.FullName = $"{source.FirstName} {source.LastName}";
    }
}

[Facet(typeof(User), Configuration = typeof(UserMapConfig))]
public partial class UserDto;

This lets you add derived properties, formatting, etc.

Facet.Extensions for LINQ/EF Core async

Install Facet.Extensions for one-line mapping helpers:

dotnet add package Facet.Extensions

Then:

using Facet.Extensions;

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

// Lists
var dtos = people.SelectFacets<Person, PersonDto>();

// IQueryable deferred projection
var query = dbContext.People.SelectFacet<Person, PersonDto>();

And with EF Core:

var dtos = await dbContext.People.ToFacetsAsync<Person, PersonDto>();

var single = await dbContext.People.FirstFacetAsync<Person, PersonDto>();

Facet - Define less, project more.

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.  net10.0 was computed.  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.

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 124 5/6/2025
1.6.0 121 4/27/2025
1.5.0 125 4/27/2025