Skip to content

Commit 8008ba0

Browse files
committed
fix: sparse fields set not applied to query
1 parent 5169fac commit 8008ba0

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

JsonApiDotnetCore.sln

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Global
204204
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x86.ActiveCfg = Release|Any CPU
205205
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x86.Build.0 = Release|Any CPU
206206
{DF9BFD82-D937-4907-B0B4-64670417115F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
207+
{DF9BFD82-D937-4907-B0B4-64670417115F}.Debug|Any CPU.Build.0 = Debug|Any CPU
207208
EndGlobalSection
208209
GlobalSection(SolutionProperties) = preSolution
209210
HideSolutionNode = FALSE

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ public virtual IQueryable<TEntity> Sort(IQueryable<TEntity> entities, List<SortQ
140140
/// <inheritdoc />
141141
public virtual async Task<TEntity> GetAsync(TId id)
142142
{
143-
return await GetQueryable().SingleOrDefaultAsync(e => e.Id.Equals(id));
143+
return await Select(GetQueryable(), _jsonApiContext.QuerySet?.Fields).SingleOrDefaultAsync(e => e.Id.Equals(id));
144144
}
145145

146146
/// <inheritdoc />
147147
public virtual async Task<TEntity> GetAndIncludeAsync(TId id, string relationshipName)
148148
{
149149
_logger?.LogDebug($"[JADN] GetAndIncludeAsync({id}, {relationshipName})");
150150

151-
var includedSet = Include(GetQueryable(), relationshipName);
151+
var includedSet = Include(Select(GetQueryable(), _jsonApiContext.QuerySet?.Fields), relationshipName);
152152
var result = await includedSet.SingleOrDefaultAsync(e => e.Id.Equals(id));
153153

154154
return result;

src/JsonApiDotNetCore/Services/EntityResourceService.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ public virtual async Task<IEnumerable<TResource>> GetAsync()
108108
if (_jsonApiContext.Options.IncludeTotalRecordCount)
109109
_jsonApiContext.PageManager.TotalRecords = await _entities.CountAsync(entities);
110110

111-
if (_jsonApiContext.QuerySet?.Fields?.Count > 0)
112-
entities = _entities.Select(entities, _jsonApiContext.QuerySet.Fields);
111+
entities = _entities.Select(entities, _jsonApiContext.QuerySet?.Fields);
113112

114113
// pagination should be done last since it will execute the query
115114
var pagedEntities = await ApplyPageQueryAsync(entities);
@@ -243,7 +242,7 @@ protected virtual IQueryable<TEntity> IncludeRelationships(IQueryable<TEntity> e
243242

244243
private async Task<TResource> GetWithRelationshipsAsync(TId id)
245244
{
246-
var query = _entities.GetQueryable().Where(e => e.Id.Equals(id));
245+
var query = _entities.Select(_entities.GetQueryable(), _jsonApiContext.QuerySet?.Fields).Where(e => e.Id.Equals(id));
247246

248247
_jsonApiContext.QuerySet.IncludedRelationships.ForEach(r =>
249248
{

0 commit comments

Comments
 (0)