Prefetch paths

To specify prefetch paths, an EntityQuery<T> has the method WithPath(prefetchPath). This method accepts one or more prefetch path element instances which can be created with the generated static properties in the generated code (see Adapter or SelfServicing)

Prefetch path elements have the following extension methods to configure them:

  • WithSubPath(prefetchPathElement[, prefetchPathElement]…). This method specifies the subpath of the prefetch path element and accepts one or more prefetch path elements which are seen as subpath elements of the prefetch path element the method is called on.
  • WithFilter(IPredicate). This method specifies the additional filter used for the prefetch path element
  • WithOrdering(sortClause[, sortClause). This method specifies the sort clauses to sort the elements in the specified order.
  • WithLimit(int). This method specifies the MaxNumberOfElementsToRetrieve or row limit of the set of elements to fetch.
  • WithExclusions(field[, field]..).This method specifies the fields to exclude for the prefetch path element. It overwrites any set of fields already set to exclude/include for the prefetch path element
  • WithInclusions(field[, field]..).This method specifies the fields to include for the prefetch path element. It overwrites any set of fields already set to exclude/include for the prefetch path element
  • WithJoins(from clause). This method is equal to QuerySpec.From**(), where it allows one to specify a series of joins with the prefetch path node to be able to filter/sort on a related entity. The specified from clause likely always starts with QueryTarget. QueryTarget is in this case converted to the type of the prefetch path element's entity. Aliasing the prefetch path node isn't possible so using QueryTarget.As/TargetAs() is not recommended.
  • WithNoCaching(). Used to specify that the prefetch path node's resultset should be excluded from resultset caching.

Example

var qf = new QueryFactory();
var q = qf.Customer
            .Where(CustomerFields.CustomerId.NotIn(new string[] { "FISSA", "PARIS" }))
            .WithPath(CustomerEntity.PrefetchPathOrders
                    .WithFilter(OrderFields.EmployeeId.Equal(2))
                    .WithOrdering(OrderFields.OrderDate.Ascending())
                    .WithLimit(3));

The above query fetches all customers which don't have the values "FISSA" or "PARIS" as CustomerId and with that fetches their first three related Order entities which have for EmployeeId the value 2. The first three are fetched, only as the prefetch path node for Order has a limit defined on itself. It will sort the fetched orders by OrderDate ascending.

Please also see the shipped example queries for various usages of the methods mentioned above.