Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(query-repository): add missing methods with 'asNoTracking' parameter to 'QueryRepository' (#55) #56

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions src/TanvirArjel.EFCore.QueryRepository/IQueryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,23 @@ Task<PaginatedList<TEntity>> GetListAsync<TEntity>(
CancellationToken cancellationToken = default)
where TEntity : class;

/// <summary>
/// This method returns a <see cref="PaginatedList{T}"/>.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="specification">An object of <see cref="PaginationSpecification{T}"/>.</param>
/// <param name="asNoTracking">A <see cref="bool"/> value which determines whether the return entity will be tracked by
/// EF Core context or not. Default value is false i.e tracking is enabled by default.
/// </param>
/// <param name="cancellationToken"> A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>Returns <see cref="PaginatedList{T}"/>.</returns>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="specification"/> is smaller than 1.</exception>
Task<PaginatedList<TEntity>> GetListAsync<TEntity>(
PaginationSpecification<TEntity> specification,
bool asNoTracking,
CancellationToken cancellationToken = default)
where TEntity : class;

/// <summary>
/// This method returns a <see cref="PaginatedList{T}"/>.
/// </summary>
Expand Down
19 changes: 17 additions & 2 deletions src/TanvirArjel.EFCore.QueryRepository/QueryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,17 @@ public async Task<List<TProjectedType>> GetListAsync<T, TProjectedType>(
.ToListAsync(cancellationToken).ConfigureAwait(false);
}

public Task<PaginatedList<T>> GetListAsync<T>(
PaginationSpecification<T> specification,
CancellationToken cancellationToken = default)
where T : class
{
return GetListAsync(specification, false, cancellationToken);
}

public async Task<PaginatedList<T>> GetListAsync<T>(
PaginationSpecification<T> specification,
bool asNoTracking,
CancellationToken cancellationToken = default)
where T : class
{
Expand All @@ -226,8 +235,14 @@ public async Task<PaginatedList<T>> GetListAsync<T>(
throw new ArgumentNullException(nameof(specification));
}

PaginatedList<T> paginatedList = await _dbContext.Set<T>().ToPaginatedListAsync(specification, cancellationToken);
return paginatedList;
IQueryable<T> query = _dbContext.Set<T>();

if (asNoTracking)
{
query = query.AsNoTracking();
}

return await query.ToPaginatedListAsync(specification, cancellationToken);;
}

public async Task<PaginatedList<TProjectedType>> GetListAsync<T, TProjectedType>(
Expand Down