DynamicWhere.ex
DynamicWhere.exv2.1.0·docs

Example 11: SelectDynamic — Dynamic Field Projection

SelectDynamic<T> accepts the same field paths as Select but projects into a dynamic result whose shape mirrors the path structure.

Direct scalars

{ "fields": ["Id", "Name", "Price"] }

Response shape:

{ "Id": 7, "Name": "Laptop Pro", "Price": 1299.99 }

Dotted path through reference navigation (nested object)

{
  "fields": ["Id", "Name", "Price", "Category.Name"]
}

Category.Name produces a nested Category object in the result.

Response shape:

{ "Id": 7, "Name": "Laptop Pro", "Price": 1299.99, "Category": { "Name": "Electronics" } }

Dotted path through collection navigation (Select lambda)

{
  "fields": ["Id", "Name", "Category.Vendors.Id"]
}

Category.Vendors is a collection — each element is projected via a Select lambda so only Id is extracted.

Response shape:

{ "Id": 7, "Name": "Laptop Pro", "Category": { "Vendors": [{ "Id": 3 }, { "Id": 7 }] } }

Multi-level dotted path (reference → collection → reference)

{
  "fields": ["Id", "Category.Vendors.Product.Name"]
}

Response shape:

{ "Id": 7, "Category": { "Vendors": [{ "Product": { "Name": "Laptop Pro" } }] } }

Multiple dotted fields merged under the same root segment

{
  "fields": ["Id", "Category.Name", "Category.Id"]
}

Category.Name and Category.Id are merged into a single nested Category object.

Response shape:

{ "Id": 7, "Category": { "Name": "Electronics", "Id": 5 } }

Whole navigation object (non-dotted)

{
  "fields": ["Id", "Name", "Category"]
}

Category has no dot → projected as the whole object.

Response shape:

{ "Id": 7, "Name": "Laptop Pro", "Category": { "Id": 5, "Name": "Electronics" } }

Whole collection (non-dotted)

{
  "fields": ["Id", "Name", "OrderItems"]
}

Response shape:

{ "Id": 7, "Name": "Laptop Pro", "OrderItems": [ { "Id": 1, "Quantity": 2 } ] }

Deep nesting through reference navigations

{
  "fields": ["Id", "Category.SubCategory.Name"]
}

Response shape:

{ "Id": 7, "Category": { "SubCategory": { "Name": "Laptops" } } }