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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Example implementation in your repository using specifications
```c#
public async Task<List<T>> ListAsync(ISpecification<T> specification, CancellationToken cancellationToken = default)
{
var query = SpecificationEvaluator.GetQuery(DbContext.Set<T>(), specification);
var query = SpecificationEvaluator.Default.GetQuery(_dbContext.Set<T>(), specification);
return await query.ToListAsync(cancellationToken);
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
<Description>EF6 plugin package to Ardalis.Specification containing EF6 evaluator and abstract repository.</Description>
<Summary>EF6 plugin package to Ardalis.Specification containing EF6 evaluator and abstract repository.</Summary>

<Version>8.0.0</Version>
<Version>9.0.0</Version>
<PackageTags>spec;specification;repository;ddd;ef;ef6;entity framework</PackageTags>
<PackageReleaseNotes>
* Added TFM for net6.0
The change log and breaking changes are listed here.
https://github.com/ardalis/Specification/issues/427
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public virtual async Task<bool> AnyAsync(CancellationToken cancellationToken = d
return await DbContext.Set<T>().AnyAsync(cancellationToken);
}

#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <inheritdoc/>
public virtual IAsyncEnumerable<T> AsAsyncEnumerable(ISpecification<T> specification)
{
Expand All @@ -184,6 +184,7 @@ public virtual IAsyncEnumerable<T> AsAsyncEnumerable(ISpecification<T> specifica
/// <paramref name="specification"/>.
/// </summary>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="evaluateCriteriaOnly">It ignores pagination and evaluators that don't affect Count.</param>
/// <returns>The filtered entities as an <see cref="IQueryable{T}"/>.</returns>
protected virtual IQueryable<T> ApplySpecification(ISpecification<T> specification, bool evaluateCriteriaOnly = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
<Description>EF Core plugin package to Ardalis.Specification containing EF Core evaluator and abstract repository.</Description>
<Summary>EF Core plugin package to Ardalis.Specification containing EF Core evaluator and abstract repository.</Summary>

<Version>8.0.0</Version>
<Version>9.0.0</Version>
<PackageTags>spec;specification;repository;ddd;ef;ef core;entity framework;entity framework core</PackageTags>
<PackageReleaseNotes>
* Added TFMs net6.0, net7.0 and net8.0
The change log and breaking changes are listed here.
https://github.com/ardalis/Specification/issues/427
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ public async Task<int> SaveChangesAsync(TContext dbContext, CancellationToken ca
/// <paramref name="specification"/>.
/// </summary>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="dbContext">The DbContext instance.</param>
/// <param name="evaluateCriteriaOnly">It ignores pagination and evaluators that don't affect Count.</param>
/// <returns>The filtered entities as an <see cref="IQueryable{T}"/>.</returns>
protected virtual IQueryable<TEntity> ApplySpecification(ISpecification<TEntity> specification, TContext dbContext, bool evaluateCriteriaOnly = false)
{
Expand All @@ -219,6 +221,7 @@ protected virtual IQueryable<TEntity> ApplySpecification(ISpecification<TEntity>
/// </summary>
/// <typeparam name="TResult">The type of the value returned by the projection.</typeparam>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="dbContext">The DbContext instance.</param>
/// <returns>The filtered projected entities as an <see cref="IQueryable{T}"/>.</returns>
protected virtual IQueryable<TResult> ApplySpecification<TResult>(ISpecification<TEntity, TResult> specification, TContext dbContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public virtual IAsyncEnumerable<T> AsAsyncEnumerable(ISpecification<T> specifica
/// <paramref name="specification"/>.
/// </summary>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="evaluateCriteriaOnly">It ignores pagination and evaluators that don't affect Count.</param>
/// <returns>The filtered entities as an <see cref="IQueryable{T}"/>.</returns>
protected virtual IQueryable<T> ApplySpecification(ISpecification<T> specification, bool evaluateCriteriaOnly = false)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Ardalis.Specification/Ardalis.Specification.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
<Description>A simple package with a base Specification class, for use in creating queries that work with Repository types.</Description>
<Summary>A simple package with a base Specification class, for use in creating queries that work with Repository types.</Summary>

<Version>8.0.0</Version>
<Version>9.0.0</Version>
<PackageTags>spec;specification;repository;ddd</PackageTags>
<PackageReleaseNotes>
* Added TFMs net6.0, net7.0 and net8.0
The change log and breaking changes are listed here.
https://github.com/ardalis/Specification/issues/427
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface ISpecificationEvaluator
/// Applies the logic encapsulated by <paramref name="specification"/> to given <paramref name="inputQuery"/>,
/// and projects the result into <typeparamref name="TResult"/>.
/// </summary>
/// <typeparam name="T">The type of the entity.</typeparam>
/// <typeparam name="TResult">The type of the result.</typeparam>
/// <param name="inputQuery">The sequence of <typeparamref name="T"/></param>
/// <param name="specification">The encapsulated query logic.</param>
Expand All @@ -17,8 +18,10 @@ public interface ISpecificationEvaluator
/// <summary>
/// Applies the logic encapsulated by <paramref name="specification"/> to given <paramref name="inputQuery"/>.
/// </summary>
/// <typeparam name="T">The type of the entity.</typeparam>
/// <param name="inputQuery">The sequence of <typeparamref name="T"/></param>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="evaluateCriteriaOnly">It ignores pagination and evaluators that don't affect Count.</param>
/// <returns>A filtered sequence of <typeparamref name="T"/></returns>
IQueryable<T> GetQuery<T>(IQueryable<T> inputQuery, ISpecification<T> specification, bool evaluateCriteriaOnly = false) where T : class;
}
6 changes: 0 additions & 6 deletions src/Ardalis.Specification/IEntity.cs

This file was deleted.

19 changes: 13 additions & 6 deletions src/Ardalis.Specification/IReadRepositoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IReadRepositoryBase<T> where T : class
/// </summary>
/// <typeparam name="TId">The type of primary key.</typeparam>
/// <param name="id">The value of the primary key for the entity to be found.</param>
/// <param name="cancellationToken"></param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation.
/// The task result contains the <typeparamref name="T" />, or <see langword="null"/>.
Expand All @@ -25,7 +25,7 @@ public interface IReadRepositoryBase<T> where T : class
/// Returns the first element of a sequence, or a default value if the sequence contains no elements.
/// </summary>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation.
/// The task result contains the <typeparamref name="T" />, or <see langword="null"/>.
Expand All @@ -36,7 +36,7 @@ public interface IReadRepositoryBase<T> where T : class
/// Returns the first element of a sequence, or a default value if the sequence contains no elements.
/// </summary>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation.
/// The task result contains the <typeparamref name="TResult" />, or <see langword="null"/>.
Expand All @@ -47,7 +47,7 @@ public interface IReadRepositoryBase<T> where T : class
/// Returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.
/// </summary>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation.
/// The task result contains the <typeparamref name="T" />, or <see langword="null"/>.
Expand All @@ -58,7 +58,7 @@ public interface IReadRepositoryBase<T> where T : class
/// Returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.
/// </summary>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation.
/// The task result contains the <typeparamref name="TResult" />, or <see langword="null"/>.
Expand All @@ -68,6 +68,7 @@ public interface IReadRepositoryBase<T> where T : class
/// <summary>
/// Finds all entities of <typeparamref name="T" /> from the database.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation.
/// The task result contains a <see cref="List{T}" /> that contains elements from the input sequence.
Expand All @@ -79,6 +80,7 @@ public interface IReadRepositoryBase<T> where T : class
/// <paramref name="specification"/>, from the database.
/// </summary>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation.
/// The task result contains a <see cref="List{T}" /> that contains elements from the input sequence.
Expand All @@ -94,6 +96,7 @@ public interface IReadRepositoryBase<T> where T : class
/// </summary>
/// <typeparam name="TResult">The type of the value returned by the projection.</typeparam>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation.
/// The task result contains a <see cref="List{TResult}" /> that contains elements from the input sequence.
Expand All @@ -105,6 +108,7 @@ public interface IReadRepositoryBase<T> where T : class
/// of the <paramref name="specification"/>.
/// </summary>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation. The task result contains the
/// number of elements in the input sequence.
Expand All @@ -114,6 +118,7 @@ public interface IReadRepositoryBase<T> where T : class
/// <summary>
/// Returns the total number of records.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation. The task result contains the
/// number of elements in the input sequence.
Expand All @@ -125,6 +130,7 @@ public interface IReadRepositoryBase<T> where T : class
/// of the <paramref name="specification"/> or not.
/// </summary>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation. The task result contains true if the
/// source sequence contains any elements; otherwise, false.
Expand All @@ -134,14 +140,15 @@ public interface IReadRepositoryBase<T> where T : class
/// <summary>
/// Returns a boolean whether any entity exists or not.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation. The task result contains true if the
/// source sequence contains any elements; otherwise, false.
/// </returns>
Task<bool> AnyAsync(CancellationToken cancellationToken = default);


#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <summary>
/// Finds all entities of <typeparamref name="T" />, that matches the encapsulated query logic of the
/// <paramref name="specification"/>, from the database.
Expand Down
10 changes: 7 additions & 3 deletions src/Ardalis.Specification/IRepositoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IRepositoryBase<T> : IReadRepositoryBase<T> where T : class
/// Adds an entity in the database.
/// </summary>
/// <param name="entity">The entity to add.</param>
/// <param name="cancellationToken"></param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation.
/// The task result contains the <typeparamref name="T" />.
Expand All @@ -25,7 +25,7 @@ public interface IRepositoryBase<T> : IReadRepositoryBase<T> where T : class
/// Adds the given entities in the database
/// </summary>
/// <param name="entities"></param>
/// <param name="cancellationToken"></param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// A task that represents the asynchronous operation.
/// </returns>
Expand All @@ -35,28 +35,31 @@ public interface IRepositoryBase<T> : IReadRepositoryBase<T> where T : class
/// Updates an entity in the database
/// </summary>
/// <param name="entity">The entity to update.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the number of state entries written to the database.</returns>
Task<int> UpdateAsync(T entity, CancellationToken cancellationToken = default);

/// <summary>
/// Updates the given entities in the database
/// </summary>
/// <param name="entities">The entities to update.</param>
/// <param name="cancellationToken"></param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the number of state entries written to the database.</returns>
Task<int> UpdateRangeAsync(IEnumerable<T> entities, CancellationToken cancellationToken = default);

/// <summary>
/// Removes an entity in the database
/// </summary>
/// <param name="entity">The entity to delete.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the number of state entries written to the database.</returns>
Task<int> DeleteAsync(T entity, CancellationToken cancellationToken = default);

/// <summary>
/// Removes the given entities in the database
/// </summary>
/// <param name="entities">The entities to remove.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the number of state entries written to the database.</returns>
Task<int> DeleteRangeAsync(IEnumerable<T> entities, CancellationToken cancellationToken = default);

Expand All @@ -65,6 +68,7 @@ public interface IRepositoryBase<T> : IReadRepositoryBase<T> where T : class
/// <paramref name="specification"/>, from the database.
/// </summary>
/// <param name="specification">The encapsulated query logic.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the number of state entries written to the database.</returns>
Task<int> DeleteRangeAsync(ISpecification<T> specification, CancellationToken cancellationToken = default);

Expand Down
3 changes: 2 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
</PropertyGroup>

<PropertyGroup>
<NoWarn>1701;1702;1591;1573;1712</NoWarn>
<!--Missing XML comment-->
<NoWarn>1591</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public async Task DeleteRangeAsync_ShouldDeleteEntitiesBySpec()
await SeedRangeAsync(countries);

var spec = new Specification<Country>();
spec.Query.Where(x=>x.Name == guid);
spec.Query.Where(x => x.Name == guid);
await repo.DeleteRangeAsync(spec);
DbContext.ChangeTracker.Clear();

Expand Down
5 changes: 1 addition & 4 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@
</PackageReference>
</ItemGroup>

<PropertyGroup>
<NoWarn>1701;1702;1591;1573;1712;0618</NoWarn>
</PropertyGroup>
</Project>
</Project>