Skip to content

LinqExtensionMethods

Craig Fowler edited this page Feb 23, 2020 · 2 revisions

The library also includes a number of extension methods designed for use by Linq-based queries, for features such as:

  • Lazy-resolution of query results, enabling the underlying ORM to batch multiple queries together.
  • Eager-fetching of objects related to the query, to retrieve 'child' & 'grandchild' entities at the same time as retrieving their parents
  • Asynchronous querying, to improve performance of I/O-bound operations

With regard to these three areas, the entry-point to this functionality is provided via a an extension methods class in the CSF.ORM namespace: QueryableExtensions. However, the functionality is not entirely static; the implementation which backs these operations may be swapped via the properties on the extension methods class.

  • EagerFetchingProvider: an implementation of IEagerlyFetchesFromQuery
  • LazyQueryingProvider: an implementation of IGetsLazyQueryResult
  • AsyncQueryingProvider: an implementation of IProvidesAsyncQuerying

Because these properties are static, they are not thread-safe. This is an unfortunate limitation inherent to the nature of extension methods.

Care should be taken when setting the properties of the QueryableExtensions class. In production it is normal to set them up once-only, during application startup. When unit testing, take care with test-parallelization settings. Ensure that tests which need to set these properties to differing values are not executed in parallel.

Clone this wiki locally