55using JsonApiDotNetCore . Extensions ;
66using JsonApiDotNetCore . Internal ;
77using JsonApiDotNetCore . Models ;
8- using Microsoft . EntityFrameworkCore ;
98using Microsoft . Extensions . Logging ;
109
1110namespace JsonApiDotNetCore . Services
@@ -50,7 +49,7 @@ public virtual async Task<IEnumerable<T>> GetAsync()
5049 entities = IncludeRelationships ( entities , _jsonApiContext . QuerySet . IncludedRelationships ) ;
5150
5251 if ( _jsonApiContext . Options . IncludeTotalRecordCount )
53- _jsonApiContext . PageManager . TotalRecords = await entities . CountAsync ( ) ;
52+ _jsonApiContext . PageManager . TotalRecords = await _entities . CountAsync ( entities ) ;
5453
5554 // pagination should be done last since it will execute the query
5655 var pagedEntities = await ApplyPageQueryAsync ( entities ) ;
@@ -72,12 +71,12 @@ private bool ShouldIncludeRelationships()
7271
7372 private async Task < T > GetWithRelationshipsAsync ( TId id )
7473 {
75- var query = _entities . Get ( ) ;
74+ var query = _entities . Get ( ) . Where ( e => e . Id . Equals ( id ) ) ;
7675 _jsonApiContext . QuerySet . IncludedRelationships . ForEach ( r =>
7776 {
7877 query = _entities . Include ( query , r ) ;
7978 } ) ;
80- return await query . FirstOrDefaultAsync ( e => e . Id . Equals ( id ) ) ;
79+ return await _entities . FirstOrDefaultAsync ( query ) ;
8180 }
8281
8382 public virtual async Task < object > GetRelationshipsAsync ( TId id , string relationshipName )
0 commit comments