66namespace JsonApiToolkit . Extensions ;
77
88/// <summary>
9- /// Provides extension methods for applying JSON:API query parameters to IQueryable data sources .
9+ /// Extension methods for applying JSON:API query parameters to IQueryable.
1010/// </summary>
11- /// <remarks>
12- /// Consolidates the application of filtering, sorting, and pagination in a single convenient extension method.
13- /// </remarks>
1411public static class QueryableExtensions
1512{
1613 /// <summary>
17- /// Applies all JSON:API query parameters to an IQueryable data source in the correct order .
14+ /// Applies all JSON:API parameters: filters → sort (defaults to Id) → pagination .
1815 /// </summary>
19- /// <typeparam name="T">The entity type of the queryable</typeparam>
20- /// <param name="query">The source IQueryable to apply parameters to</param>
21- /// <param name="parameters">The complete set of JSON:API query parameters</param>
22- /// <returns>A new IQueryable with all query parameters applied</returns>
23- /// <remarks>
24- /// Applies parameters in the following order:
25- /// <list type="number">
26- /// <item>
27- /// <description>Filtering - narrows the result set based on field conditions</description>
28- /// </item>
29- /// <item>
30- /// <description>Sorting - orders the results (defaults to Id ascending if not specified)</description>
31- /// </item>
32- /// <item>
33- /// <description>Pagination - limits the number of results and supports paging</description>
34- /// </item>
35- /// </list>
36- /// This is the recommended method for applying all JSON:API query parameters in a single operation.
37- /// </remarks>
3816 public static IQueryable < T > ApplyJsonApiParameters < T > (
3917 this IQueryable < T > query ,
4018 QueryParameters parameters
@@ -58,12 +36,8 @@ QueryParameters parameters
5836 }
5937
6038 /// <summary>
61- /// Dynamically applies EF Core Include() calls for each include path (dot notation supported ).
39+ /// Applies EF Core Include() for each path (supports dot notation).
6240 /// </summary>
63- /// <typeparam name="T">The entity type.</typeparam>
64- /// <param name="query">The source queryable.</param>
65- /// <param name="includePaths">A list of include paths (e.g. "todo", "todo.category").</param>
66- /// <returns>The queryable with all includes applied.</returns>
6741 public static IQueryable < T > ApplyIncludes < T > (
6842 this IQueryable < T > query ,
6943 List < string > ? includePaths
@@ -81,17 +55,9 @@ public static IQueryable<T> ApplyIncludes<T>(
8155 }
8256
8357 /// <summary>
84- /// Dynamically applies EF Core Include() calls using AsSingleQuery() to prevent split query issues.
58+ /// Applies EF Core Include() using AsSingleQuery() to prevent split query issues with pagination.
59+ /// Forces single query with JOINs instead of separate queries.
8560 /// </summary>
86- /// <typeparam name="T">The entity type.</typeparam>
87- /// <param name="query">The source queryable.</param>
88- /// <param name="includePaths">A list of include paths (e.g. "todo", "todo.category").</param>
89- /// <returns>The queryable with all includes applied using single query mode.</returns>
90- /// <remarks>
91- /// Use this method when pagination is present to avoid EF Core split query optimization issues
92- /// that can cause includes to load data for wrong entities or no entities at all.
93- /// Forces EF Core to use a single query with JOINs instead of separate queries.
94- /// </remarks>
9561 public static IQueryable < T > ApplyIncludesSingleQuery < T > (
9662 this IQueryable < T > query ,
9763 List < string > ? includePaths
@@ -101,7 +67,6 @@ public static IQueryable<T> ApplyIncludesSingleQuery<T>(
10167 if ( includePaths == null || includePaths . Count == 0 )
10268 return query ;
10369
104- // Force single query to prevent EF Core split query issues with pagination
10570 query = query . AsSingleQuery ( ) ;
10671
10772 foreach ( string path in includePaths )
0 commit comments