How To: Force Contains to Use Only IN Clause for Backend Side Filtering

1 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 02 Jun 2014 Link to this post


    Telerik Data Access:


    .NET Version:

    3.5 C# and VB

    Visual Studio Version:


    The Telerik Data Access implementation of the Contains IQueryable extension method uses the limits of the backend for maximum number of IN values and maximum number of query parameters to smartly switch between using IN clause or Temporary Tables for the filtering on the backend side. These projects show how to influence the behavior of Contains in order to force it to always use IN clause and handle scenarios where the size of the in memory collection used for the filtering is beyond the said limits of the backend. This will be useful in cases where you need to finely tune the performance of your LINQ queries using Contains or your application does not have the required privileges to create Temporary Tables. The following steps are taken in the creation of the projects:
    1. Expose the BackendInformation object for your model as shown here.
    2. Save the original values of the MaximumNumberOfInValues and MaximumNumberOfQueryParameters properties.
    3. Set the values of the MaximumNumberOfInValues and MaximumNumberOfQueryParameters properties to be higher than both the original limits and the size of the in memory collection against which Contains will be used.
    4. This will prevent the usage of Temporary Tables. Instead a DataStoreException will be thrown when the actual backend limits are hit.
    5. To handle situations where the size of the in memory collection used for the filtering goes beyond the actual backend limits, the collection is partitioned to chunks small enough to satisfy the limits.
    6. As the limits set through BackendInformation affect the behavior of every existing and future instance of OpenAccessContext, the original values of the limits are restored.

Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.