CompiledQuery.Compile Method

Creates a new delegate that represents the compiled query.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

The generic arguments to this method are (in order):

  • TDataContext. Constrained to be a DataContext. It represents the DataContext that must be passed in when executing the delegate returned by the Compile method.

  • TArg0, …, TArg2. Represents the types of the parameters that have to be passed in when executing the delegate returned by the Compile method.

  • TResult. Represents the type of T in the IEnumerable<T> returned when executing the delegate returned by the Compile method.

Passing a query expression that does not use the TDataContext parameter generates an exception when the returning delegate is executed for the first time.

The Return Value

Func<TDataContext, TArg0, TArg1, …, TArg2, TResult>, representing the delegate that can be cached. At the time when this delegate is executed, the query will be compiled. Observe the following notes:

  • Passing null to the first argument typed TDataContext generates a run-time exception.

  • It is an error to re-execute a compiled query using a DataContext that contains a DataLoadOptions different from the one originally used to compile the query (the first time it is executed). The reason for this behavior is that compiling the query requires information that is contained in the DataShape. When a query is executed again using a different DataShape, the cached query becomes invalid and an error is generated.

  • If a new query operator is applied to the result of the delegate execution, an exception is generated.

  • When you want to execute a query operator over the result of executing a compiled query, you must translate the result to a list before operating on it.

Community Additions