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

Is there any plan (Is it necessary?) to add specification signatures to the IReadOnlyBasicRepository interface #15242

Open
1 task done
colinin opened this issue Dec 28, 2022 · 3 comments
Labels
Milestone

Comments

@colinin
Copy link

colinin commented Dec 28, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

You can enhance the Specification query approach, making it easier for users to combine query results.

Describe the solution you'd like

For example:

Interface:

public interface IReadOnlyBasicRepository<TEntity> : IRepository where TEntity : class, IEntity
{
    // Added a specification list query api
    Task<List<TEntity>> GetListAsync(ISpecification<TEntity> specification, bool includeDetails = false, CancellationToken cancellationToken = default);

    // Added a specification paged list query api
    Task<List<TEntity>> GetPagedListAsync(ISpecification<TEntity> specification, bool includeDetails = false, string sorting = null, int skipCount = 0, int maxResultCount = 10, CancellationToken cancellationToken = default);

    // // Added a specification count query api
    Task<long> GetCountAsync(ISpecification<TEntity> specification, CancellationToken cancellationToken = default);
}

Implement:

public abstract class EfDemoRepository<TDbContext, TEntity> : 
    EfCoreRepository<TDbContext, TEntity>,
    IReadOnlyBasicRepository<TEntity> where TEntity : class, IEntity
{

    public ReadOnlyBasicRepository(
        IDbContextProvider<TDbContext> dbContextProvider)
        : base(dbContextProvider)
    {
    }

    public async virtual Task<List<TEntity>> GetListAsync(ISpecification<TEntity> specification, bool includeDetails = false, CancellationToken cancellationToken = default)
    {
        return await (await GetDbSetAsync())
            .Where(specification.ToExpression())
            .ToListAsync(GetCancellationToken(cancellationToken));
    }

    public async virtual Task<List<TEntity>> GetPagedListAsync(ISpecification<TEntity> specification, bool includeDetails = false, string sorting = null, int skipCount = 0, int maxResultCount = 10, CancellationToken cancellationToken = default)
    {
        sorting ??= "id";
        return await (await GetDbSetAsync())
            .Where(specification.ToExpression())
            .OrderBy(sorting)
            .PageBy(skipCount, maxResultCount)
            .ToListAsync(GetCancellationToken(cancellationToken));
    }

    public async virtual Task<long> GetCountAsync(ISpecification<TEntity> specification, CancellationToken cancellationToken = default)
    {
        return await (await GetDbSetAsync())
            .Where(specification.ToExpression())
            .LongCountAsync(GetCancellationToken(cancellationToken));
    }
}

Additional context

No response

@colinin
Copy link
Author

colinin commented Dec 28, 2022

Maybe it has a similar function

Task<List<TEntity>> GetListAsync(
[NotNull] Expression<Func<TEntity, bool>> predicate,
bool includeDetails = false,
CancellationToken cancellationToken = default);
}

@berkansasmaz
Copy link
Member

What do you think about it @maliming?

@maliming
Copy link
Member

We can consider doing this.

@maliming maliming modified the milestones: 7.3-preview, backlog Dec 29, 2022
@berkansasmaz berkansasmaz removed their assignment Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants