Skip to content

Commit c91b80b

Browse files
committed
fix(repository): only apply select if there are fields in query
also add logging
1 parent 6c8e9e2 commit c91b80b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public DefaultEntityRepository(
4949

5050
public virtual IQueryable<TEntity> Get()
5151
{
52-
return _dbSet.Select(_jsonApiContext.QuerySet?.Fields);
52+
if(_jsonApiContext.QuerySet?.Fields != null && _jsonApiContext.QuerySet.Fields.Any())
53+
return _dbSet.Select(_jsonApiContext.QuerySet?.Fields);
54+
55+
return _dbSet;
5356
}
5457

5558
public virtual IQueryable<TEntity> Filter(IQueryable<TEntity> entities, FilterQuery filterQuery)
@@ -85,11 +88,15 @@ public virtual async Task<TEntity> GetAsync(TId id)
8588

8689
public virtual async Task<TEntity> GetAndIncludeAsync(TId id, string relationshipName)
8790
{
91+
_logger.LogDebug($"[JADN] GetAndIncludeAsync({id}, {relationshipName})");
92+
8893
var result = await Get()
8994
.Include(relationshipName)
9095
.Where(e => e.Id.Equals(id))
9196
.ToListAsync();
92-
97+
98+
_logger.LogDebug($"[JADN] Found {result.Count} entity");
99+
93100
return result.SingleOrDefault();
94101
}
95102

0 commit comments

Comments
 (0)