Skip to content

Commit 61c5b4d

Browse files
committed
chore(EntityResourceService): consolidate ShouldIncludeRelationships check
1 parent e1e4120 commit 61c5b4d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/JsonApiDotNetCore/Services/EntityResourceService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using JsonApiDotNetCore.Data;
55
using JsonApiDotNetCore.Extensions;
66
using JsonApiDotNetCore.Internal;
7-
using JsonApiDotNetCore.Internal.Query;
87
using JsonApiDotNetCore.Models;
98
using Microsoft.EntityFrameworkCore;
109
using Microsoft.Extensions.Logging;
@@ -47,7 +46,7 @@ public virtual async Task<IEnumerable<T>> GetAsync()
4746

4847
entities = ApplySortAndFilterQuery(entities);
4948

50-
if (_jsonApiContext.QuerySet?.IncludedRelationships != null && _jsonApiContext.QuerySet.IncludedRelationships.Count > 0)
49+
if (ShouldIncludeRelationships())
5150
entities = IncludeRelationships(entities, _jsonApiContext.QuerySet.IncludedRelationships);
5251

5352
if (_jsonApiContext.Options.IncludeTotalRecordCount)
@@ -61,13 +60,16 @@ public virtual async Task<IEnumerable<T>> GetAsync()
6160
public virtual async Task<T> GetAsync(TId id)
6261
{
6362
T entity;
64-
if (_jsonApiContext.QuerySet?.IncludedRelationships != null)
63+
if (ShouldIncludeRelationships())
6564
entity = await GetWithRelationshipsAsync(id);
6665
else
6766
entity = await _entities.GetAsync(id);
6867
return entity;
6968
}
7069

70+
private bool ShouldIncludeRelationships()
71+
=> (_jsonApiContext.QuerySet?.IncludedRelationships != null && _jsonApiContext.QuerySet.IncludedRelationships.Count > 0);
72+
7173
private async Task<T> GetWithRelationshipsAsync(TId id)
7274
{
7375
var query = _entities.Get();

0 commit comments

Comments
 (0)