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.
// The following example invokes such a compiled query in the main // program. public IEnumerable<Customer> GetCustomersByCity(string city)
var myDb = GetNorthwind();
return Queries.CustomersByCity(myDb, city);
You cannot currently store (in static variables) queries that return an anonymous type, because the type has no name to provide as a generic argument. The following example shows how you can work around the issue by creating a type that can represent the result, and then use it as a generic argument.