Facet 1.5.0

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

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 = "hidden@example.com",
    Age = 33,
    RawId = Guid.NewGuid()
};

var dto = new PersonDto(person);

Advanced mapping support

1. Constructor-based custom logic

Install mapping package:

dotnet add package Facet.Mapping

Define your configuration:

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 attribute with Configuration:

[Facet(
    typeof(User),
    exclude: new[] { "Password" },
    Configuration = typeof(UserMapConfig)]
public partial class UserDto
{
    public string FullName { get; set; }
    public string RegisteredText { get; set; }
}

2. LINQ expression projection

Enable SQL-friendly projection:

[Facet(
    typeof(PersonEntity),
    GenerateExpressionProjection = true)]
public partial class PersonDto { }

Use with EF Core or other IQueryable<T>:

var dtos = dbContext.People
    .Where(p => p.IsActive)
    .Select(PersonDto.Projection)
    .ToList();

3. Chaining Facets

You can stack facets in-memory:

// 1) Entity → DTO
[Facet(typeof(Person), GenerateExpressionProjection = true)]
public partial class PersonDto { }

// 2DTO → ViewModel
[Facet(typeof(PersonDto))]
public partial class PersonViewModel { /* add UI props */ }

// 1) SQL → DTO
var dtos = dbContext.People.Select(PersonDto.Projection).ToList();
// 2) In-memory → VM
var vms  = dtos.Select(PersonViewModel.Projection.Compile()).ToList();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Facet:

Package Downloads
Facet.Extensions

Provider-agnostic extension methods for Facet.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.7.0 0 9/12/2025
2.6.2 8 9/12/2025
2.6.1 87 9/10/2025
2.6.0 94 9/9/2025
2.5.0 285 9/4/2025
2.4.8 201 9/3/2025
2.4.7 243 9/1/2025
2.4.6 132 9/1/2025
2.4.5 202 8/30/2025
2.4.4 416 8/27/2025
2.4.3 189 8/27/2025
2.4.2 181 8/27/2025
2.4.1 215 8/26/2025
2.4.0 204 8/26/2025
2.3.0 1,546 8/20/2025
2.2.0 159 8/20/2025
2.1.0 267 8/18/2025
2.0.1 766 8/5/2025
2.0.0 155 8/4/2025
1.9.3 197 7/4/2025
1.9.1 156 7/3/2025
1.9.0 154 7/3/2025
1.8.0 253 6/4/2025
1.7.0 212 5/6/2025
1.6.0 180 4/27/2025
1.5.0 219 4/26/2025
1.4.0 144 4/25/2025
1.3.0 171 4/24/2025
1.2.0 176 4/24/2025
1.1.1 176 4/23/2025
1.1.0 181 4/23/2025
1.0.2 376 4/23/2025
1.0.1 191 4/23/2025
1.0.0 191 4/23/2025
0.1.0 183 4/22/2025