Skip to content

Expressions Property Access

quyvu edited this page Oct 13, 2026 · 2 revisions

Property Access

Navigate through object relationships with simple, nested, and null-safe property access.

Simple Properties

Access simple properties directly:

Name
Email
Status

Null-Safe Property Access

Use ? to return null instead of throwing an exception when the property is null:

Country?
Address?.City

Nested Navigation

Access nested properties through multiple levels using dot notation:

Country.Province.City.Name
Order.Customer.Address.ZipCode

Null-Safe Navigation

Combine null-safe operator with navigation for safe deep access:

Country?.Province?.City.Name
Order?.Customer?.Email

Usage with FxMap Profiles

// Distributed keys
public sealed class UserDistributedKey : IDistributedKey;
public sealed class ProvinceDistributedKey : IDistributedKey;
 
// Entity configs (data-provider side)
public class UserConfig : EntityConfigureOf<User>
{
    protected override void Configure()
    {
        Id(x => x.Id);
        DefaultProperty(x => x.Name);
        UseDistributedKey<UserDistributedKey>();
    }
}
 
public class ProvinceConfig : EntityConfigureOf<Province>
{
    protected override void Configure()
    {
        Id(x => x.Id);
        DefaultProperty(x => x.Name);
        UseDistributedKey<ProvinceDistributedKey>();
    }
}
 
// DTO and profile - Navigate through relationships
public class UserLocationResponse
{
    public string UserId { get; set; }
    public string UserName { get; set; }
    public string ProvinceName { get; set; }
    public string CountryName { get; set; }
    public string? SafeCountryName { get; set; }
}
 
public class UserLocationResponseProfile : ProfileOf<UserLocationResponse>
{
    protected override void Configure()
    {
        UseDistributedKey<UserDistributedKey>()
            .Of(x => x.UserId)
            .For(x => x.UserName)                          // default property
            .For(x => x.ProvinceName, "Province.Name")     // one-level navigation
            .For(x => x.CountryName, "Province.Country.Name") // multi-level navigation
            .For(x => x.SafeCountryName, "Province?.Country?.Name"); // null-safe
    }
}

How It Works

When you use navigation expressions, FxMap intelligently handles the data fetching:

  • Single Service: Uses optimized database queries (e.g., SQL JOINs with EF Core)

  • Microservices: Automatically makes transport calls to fetch related data

  • Batching: Groups multiple queries for optimal performance

Null-Safe Operator Notes

  • The ? operator can be used on any segment in a navigation chain
  • Returns null instead of throwing NullReferenceException
  • If any relationship is null, the target property will remain its default value

Source: https://fxmapper.net/docs/expressions/navigation/ — the website is always the most up to date version.

Clone this wiki locally