/// <summary> /// Returns a new query which is configured to load the collections in the query results through separate database queries. /// </summary> /// <remarks> /// <para> /// This behavior can significantly improve performance when the query loads multiple collections. /// However, since separate queries are used, this can result in inconsistent results when concurrent updates occur. /// Serializable or snapshot transactions can be used to mitigate this /// and achieve consistency with split queries, but that may bring other performance costs and behavioral difference. /// </para> /// <para> /// The default query splitting behavior for queries can be controlled by /// <see cref="RelationalDbContextOptionsBuilder{TBuilder, TExtension}.UseQuerySplittingBehavior(QuerySplittingBehavior)" />. /// </para> /// <para> /// See <see href="https://aka.ms/efcore-docs-split-queries">EF Core split queries</see> for more information and examples. /// </para> /// </remarks> /// <typeparam name="TEntity">The type of entity being queried.</typeparam> /// <param name="source">The source query.</param> /// <returns>A new query where collections will be loaded through separate database queries.</returns> public static IQueryable <TEntity> AsSplitQuery <TEntity>( this IQueryable <TEntity> source) where TEntity : class => source.Provider is EntityQueryProvider ? source.Provider.CreateQuery <TEntity>( Expression.Call(AsSplitQueryMethodInfo.MakeGenericMethod(typeof(TEntity)), source.Expression)) : source;
/// <summary> /// <para> /// Returns a new query which is configured to load the collections in the query results through separate database queries. /// </para> /// <para> /// This behavior can significantly improve performance when the query loads multiple collections. /// However, since separate queries are used, this can result in inconsistent results when concurrent updates occur. /// Serializable or snapshot transactions can be used to mitigate this /// and achieve consistency with split queries, but that may bring other performance costs and behavioral difference. /// </para> /// <para> /// The default query splitting behavior for queries can be controlled by /// <see cref="RelationalDbContextOptionsBuilder{TBuilder, TExtension}.UseQuerySplittingBehavior(QuerySplittingBehavior)" />. /// </para> /// </summary> /// <typeparam name="TEntity"> The type of entity being queried. </typeparam> /// <param name="source"> The source query. </param> /// <returns> A new query where collections will be loaded through separate database queries. </returns> public static IQueryable <TEntity> AsSplitQuery <TEntity>( [NotNull] this IQueryable <TEntity> source) where TEntity : class { Check.NotNull(source, nameof(source)); return(source.Provider is EntityQueryProvider ? source.Provider.CreateQuery <TEntity>( Expression.Call(AsSplitQueryMethodInfo.MakeGenericMethod(typeof(TEntity)), source.Expression)) : source); }