Skip to content

Commit 77b8dc4

Browse files
committed
feat(controller): get total records
1 parent da30931 commit 77b8dc4

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/JsonApiDotNetCore/Controllers/JsonApiController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public virtual async Task<IActionResult> GetAsync()
6464
if (_jsonApiContext.QuerySet != null && _jsonApiContext.QuerySet.IncludedRelationships != null && _jsonApiContext.QuerySet.IncludedRelationships.Count > 0)
6565
entities = IncludeRelationships(entities, _jsonApiContext.QuerySet.IncludedRelationships);
6666

67+
if (_jsonApiContext.Options.IncludeTotalRecordCount)
68+
_jsonApiContext.TotalRecords = await entities.CountAsync();
69+
6770
// pagination should be done last since it will execute the query
6871
var pagedEntities = await ApplyPageQueryAsync(entities);
6972

src/JsonApiDotNetCore/Services/IJsonApiContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ public interface IJsonApiContext
1515
QuerySet QuerySet { get; set; }
1616
bool IsRelationshipData { get; set; }
1717
List<string> IncludedRelationships { get; set; }
18+
int TotalRecords { get; set; }
1819
}
1920
}

0 commit comments

Comments
 (0)