FetchXMLBuilder

The FetchXMLBuilder class provides a fluent API for building and manipulating FetchXML queries programmatically. Instead of constructing raw XML strings, you can use strongly-typed methods to define entities, columns, filters, conditions, sort orders, and link-entities.

React note

FetchXMLBuilder is a server-side Blazor utility — there's no React equivalent. React callers compose FetchXML as string literals (template strings) and pass them directly to ppp.retrieveRecordsAsync(fetchXml). The server still does the heavy lifting (filter merging, paging, security trimming) once the FetchXML arrives.

Creating a Query

Create a new FetchXMLBuilder with an empty query, or parse an existing FetchXML string.

Selecting Columns

Add individual columns with AddColumn, or set AllColumns = true to retrieve all columns. Setting AllColumns removes any individually added columns.

Adding Filters

Add filters to an entity or link-entity with AddFilter, then add conditions to the filter. Each condition specifies a column, operator, and value.

Joining Related Tables

Use AddLinkEntity to join a related table. Set the TableName, From, To, and Operator properties to define the join. Filters can be added to link-entities just like the main entity.

Sorting Results

Use AddSortOrder to define the sort order. You can specify the column name and whether to sort in descending order.

Paging

Control paging with the Count, Page, and PagingCookie properties on the Fetch element. Set ReturnRecordCount = true to include the total record count in the results.

Parsing Existing FetchXML

Pass an existing FetchXML string to the constructor to parse and manipulate it. This is useful for modifying queries from views or other sources.

Generating the FetchXML String

Call ToString() to generate the FetchXML string. The output is deterministically ordered: attributes, then sort orders, then filters, then link-entities. Within each group, elements are sorted alphabetically.

FetchXMLBuilder Class

Properties

Name
Type
Default
Description
FetchFetchElement
Gets the root fetch element of the query.
Name: Fetch
Type: FetchElement
Description: Gets the root fetch element of the query.