DynamicWhere.ex
DynamicWhere.exv3.4.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. The body is a bare JSON array of strings; inside a Filter the same list goes under selects.

Direct scalars

["Id", "Name", "Price"]

Response shape:

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

Dotted path through reference navigation (nested object)

["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)

["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)

["Id", "Category.Vendors.Product.Name"]

Response shape:

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

Multiple dotted fields merged under the same root segment

["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)

["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)

["Id", "Name", "OrderItems"]

Response shape:

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

Deep nesting through reference navigations

["Id", "Category.SubCategory.Name"]

Response shape:

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