Repository navigation
Expressions Projections
quyvu edited this page Oct 14, 2026
·
3 revisions
Select and transform specific properties using projection syntax with aliases and computed expressions.
Orders.{Id, Status, Total}
Orders.{Id, Customer.Name, OrderDate}
{Id, Name, Email}
{Id, Country.Name, Status}
Rename output properties using the as keyword:
{Id, Country.Name as CountryName, Status as OrderStatus}
Orders.{Id, Total as Amount, Customer.Name as Buyer}
Orders.{Id, Total:round(2) as RoundedTotal, Name:upper}
{CreatedAt:format('yyyy-MM-dd') as Date, Name:trim as CleanName}
Computed expressions require parentheses () and an alias:
{(Nickname ?? Name) as DisplayName}
{(Status = 'Done' ? 'Yes' : 'No') as IsDone}
{(Total:multiply(1.1)) as TotalWithTax}
Orders.{Id, (Items:count > 5 ? 'Large' : 'Small') as Size}
// DTOs
public class UserSummaryDto
{
public string Id { get; set; }
public string DisplayName { get; set; }
public string Location { get; set; }
public string Status { get; set; }
public int TotalOrders { get; set; }
}
public class OrderSummaryDto
{
public string Id { get; set; }
public decimal Amount { get; set; }
public string Buyer { get; set; }
public string Size { get; set; }
}
public class UserProfileResponse
{
public string UserId { get; set; }
public UserSummaryDto Summary { get; set; }
public List<OrderSummaryDto> RecentOrders { get; set; }
}
public class UserProfileResponseProfile : ProfileOf<UserProfileResponse>
{
protected override void Configure()
{
UseDistributedKey<UserDistributedKey>()
.Of(x => x.UserId)
.For(x => x.Summary, @"{
Id,
(Nickname ?? Name) as DisplayName,
(Address?.City ?? 'Unknown') as Location,
(IsActive = true ? 'Active' : 'Inactive') as Status,
Orders:count as TotalOrders
}")
.For(x => x.RecentOrders, @"Orders:where(Status = 'Done'):orderBy(OrderDate desc):limit(10).{
Id,
Total:round(2) as Amount,
Customer.Name as Buyer,
(Items:count > 5 ? 'Large' : 'Small') as Size
}");
}
}# Complex projection combining multiple features
Orders:where(Status = 'Done'):orderBy(OrderDate desc):limit(10).{
Id,
OrderDate:format('yyyy-MM-dd') as Date,
Total:round(2) as Amount,
Customer.Name as Buyer,
(Items:count > 5 ? 'Bulk' : 'Standard') as OrderType,
(Total > 500 ? 'High Value' : 'Regular') as ValueTier
}
# Root projection with multiple computed expressions
{
Id,
(Nickname ?? FirstName ?? 'Anonymous') as DisplayName,
(Address?.City ?? Address?.Country ?? 'Unknown') as Location,
(IsActive ? 'Active' : 'Inactive') as Status,
Orders:count as TotalOrders,
Orders:where(Status = 'Done'):sum(Total) as TotalSpent
}
- Simple properties can be used directly:
{Id, Name} - Nested properties use dot notation:
{Country.Name} - Use
asfor aliases:{Name as FullName} - Computed expressions need parentheses + alias:
{(A ?? B) as Value} - Functions can be used with or without alias:
{Name:upper}or{Name:upper as UpperName}
Source: https://fxmapper.net/docs/expressions/object-mapping/ — the website is always the most up to date version.
Introduction
Getting Started
Configuration
- Service Registration
- Entities & Profiles
- Handlers
- Pipelines
- Strongly Typed IDs
- Error Handling
- Retry Policy
- Supervisor
- Telemetry
- Kestrel (HTTP/2)
- Analyzers
Expressions
- Overview
- Property Access
- Filters, Sorting & Paging
- Functions
- Aggregations
- Projections
- Coalesce & Ternary
- GroupBy
Data Providers
Transports
Integrations
Quality
AI Assistants
Migration
Release Notes