Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,8 @@ public DefaultEntityRepository(
_resourceDefinition = resourceDefinition;
}



public virtual IQueryable<TEntity> Get()
{
if (_jsonApiContext.QuerySet?.Fields != null && _jsonApiContext.QuerySet.Fields.Count > 0)
return _dbSet.Select(_jsonApiContext.QuerySet?.Fields);

return _dbSet;
}

/// <inheritdoc />
public virtual IQueryable<TEntity> GetQueryable()
public virtual IQueryable<TEntity> Get()
=> _dbSet;

public virtual IQueryable<TEntity> Select(IQueryable<TEntity> entities, List<string> fields)
Expand Down Expand Up @@ -140,15 +130,15 @@ public virtual IQueryable<TEntity> Sort(IQueryable<TEntity> entities, List<SortQ
/// <inheritdoc />
public virtual async Task<TEntity> GetAsync(TId id)
{
return await Select(GetQueryable(), _jsonApiContext.QuerySet?.Fields).SingleOrDefaultAsync(e => e.Id.Equals(id));
return await Select(Get(), _jsonApiContext.QuerySet?.Fields).SingleOrDefaultAsync(e => e.Id.Equals(id));
}

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

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

return result;
Expand Down
3 changes: 0 additions & 3 deletions src/JsonApiDotNetCore/Data/IEntityReadRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public interface IEntityReadRepository<TEntity, in TId>
/// The base GET query. This is a good place to apply rules that should affect all reads,
/// such as authorization of resources.
/// </summary>
IQueryable<TEntity> GetQueryable();

[Obsolete("This method has been deprecated, use GetQueryable() instead")]
IQueryable<TEntity> Get();

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Services/EntityResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public virtual async Task<bool> DeleteAsync(TId id)

public virtual async Task<IEnumerable<TResource>> GetAsync()
{
var entities = _entities.GetQueryable();
var entities = _entities.Get();

entities = ApplySortAndFilterQuery(entities);

Expand Down Expand Up @@ -242,7 +242,7 @@ protected virtual IQueryable<TEntity> IncludeRelationships(IQueryable<TEntity> e

private async Task<TResource> GetWithRelationshipsAsync(TId id)
{
var query = _entities.Select(_entities.GetQueryable(), _jsonApiContext.QuerySet?.Fields).Where(e => e.Id.Equals(id));
var query = _entities.Select(_entities.Get(), _jsonApiContext.QuerySet?.Fields).Where(e => e.Id.Equals(id));

_jsonApiContext.QuerySet.IncludedRelationships.ForEach(r =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public AuthorizedTodoItemsRepository(
_authService = authService;
}

public override IQueryable<TodoItem> GetQueryable()
public override IQueryable<TodoItem> Get()
{
return base.GetQueryable().Where(todoItem => todoItem.OwnerId == _authService.CurrentUserId);
return base.Get().Where(todoItem => todoItem.OwnerId == _authService.CurrentUserId);
}
}
}