Skip to content
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
46 changes: 30 additions & 16 deletions src/UnitOfWork/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ TResult GetFirstOrDefault<TResult>(Expression<Func<TEntity, TResult>> selector,
/// <param name="orderBy">A function to order elements.</param>
/// <param name="include">A function to include navigation properties</param>
/// <param name="disableTracking"><c>true</c> to disable changing tracking; otherwise, <c>false</c>. Default to <c>true</c>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <param name="ignoreQueryFilters">Ignore query filters</param>
/// <returns>An <see cref="IPagedList{TEntity}"/> that contains elements that satisfy the condition specified by <paramref name="predicate"/>.</returns>
/// <remarks>Ex: This method defaults to a read-only, no-tracking query.</remarks>
Task<TResult> GetFirstOrDefaultAsync<TResult>(Expression<Func<TEntity, TResult>> selector,
Expression<Func<TEntity, bool>> predicate = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = null,
CancellationToken cancellationToken = default,
bool disableTracking = true,
bool ignoreQueryFilters = false);

Expand All @@ -182,13 +184,15 @@ Task<TResult> GetFirstOrDefaultAsync<TResult>(Expression<Func<TEntity, TResult>>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <param name="orderBy">A function to order elements.</param>
/// <param name="include">A function to include navigation properties</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <param name="disableTracking"><c>true</c> to disable changing tracking; otherwise, <c>false</c>. Default to <c>true</c>.</param>
/// <param name="ignoreQueryFilters">Ignore query filters</param>
/// <returns>An <see cref="IPagedList{TEntity}"/> that contains elements that satisfy the condition specified by <paramref name="predicate"/>.</returns>
/// <remarks>Ex: This method defaults to a read-only, no-tracking query. </remarks>
Task<TEntity> GetFirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = null,
CancellationToken cancellationToken = default,
bool disableTracking = true,
bool ignoreQueryFilters = false);

Expand Down Expand Up @@ -220,7 +224,7 @@ Task<TEntity> GetFirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate =
/// <param name="keyValues">The values of the primary key for the entity to be found.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task{TEntity}"/> that represents the asynchronous find operation. The task result contains the found entity or null.</returns>
ValueTask<TEntity> FindAsync(object[] keyValues, CancellationToken cancellationToken);
ValueTask<TEntity> FindAsync(CancellationToken cancellationToken = default, params object[] keyValues);

/// <summary>
/// Gets all entities. This method is not recommended
Expand All @@ -247,22 +251,25 @@ IQueryable<TEntity> GetAll(Expression<Func<TEntity, bool>> predicate = null,
/// <summary>
/// Gets all entities. This method is not recommended
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>The <see cref="IQueryable{TEntity}"/>.</returns>
Task<IList<TEntity>> GetAllAsync();
Task<IList<TEntity>> GetAllAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Gets all entities. This method is not recommended
/// </summary>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <param name="orderBy">A function to order elements.</param>
/// <param name="include">A function to include navigation properties</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <param name="disableTracking"><c>true</c> to disable changing tracking; otherwise, <c>false</c>. Default to <c>true</c>.</param>
/// <param name="ignoreQueryFilters">Ignore query filters</param>
/// <returns>An <see cref="IPagedList{TEntity}"/> that contains elements that satisfy the condition specified by <paramref name="predicate"/>.</returns>
/// <remarks>Ex: This method defaults to a read-only, no-tracking query.</remarks>
Task<IList<TEntity>> GetAllAsync(Expression<Func<TEntity, bool>> predicate = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = null,
CancellationToken cancellationToken = default,
bool disableTracking = true,
bool ignoreQueryFilters = false);

Expand All @@ -277,8 +284,9 @@ Task<IList<TEntity>> GetAllAsync(Expression<Func<TEntity, bool>> predicate = nul
/// Gets async the count based on a predicate.
/// </summary>
/// <param name="predicate"></param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns></returns>
Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate = null);
Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate = null, CancellationToken cancellationToken = default);

/// <summary>
/// Gets the long count based on a predicate.
Expand All @@ -291,8 +299,9 @@ Task<IList<TEntity>> GetAllAsync(Expression<Func<TEntity, bool>> predicate = nul
/// Gets async the long count based on a predicate.
/// </summary>
/// <param name="predicate"></param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns></returns>
Task<long> LongCountAsync(Expression<Func<TEntity, bool>> predicate = null);
Task<long> LongCountAsync(Expression<Func<TEntity, bool>> predicate = null, CancellationToken cancellationToken = default);

/// <summary>
/// Gets the max based on a predicate.
Expand All @@ -306,9 +315,10 @@ Task<IList<TEntity>> GetAllAsync(Expression<Func<TEntity, bool>> predicate = nul
/// Gets the async max based on a predicate.
/// </summary>
/// <param name="predicate"></param>
/// /// <param name="selector"></param>
/// <param name="selector"></param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>decimal</returns>
Task<T> MaxAsync<T>(Expression<Func<TEntity, bool>> predicate = null, Expression<Func<TEntity, T>> selector = null);
Task<T> MaxAsync<T>(Expression<Func<TEntity, bool>> predicate = null, Expression<Func<TEntity, T>> selector = null, CancellationToken cancellationToken = default);

/// <summary>
/// Gets the min based on a predicate.
Expand All @@ -323,8 +333,9 @@ Task<IList<TEntity>> GetAllAsync(Expression<Func<TEntity, bool>> predicate = nul
/// </summary>
/// <param name="predicate"></param>
/// <param name="selector"></param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>decimal</returns>
Task<T> MinAsync<T>(Expression<Func<TEntity, bool>> predicate = null, Expression<Func<TEntity, T>> selector = null);
Task<T> MinAsync<T>(Expression<Func<TEntity, bool>> predicate = null, Expression<Func<TEntity, T>> selector = null, CancellationToken cancellationToken = default);

/// <summary>
/// Gets the average based on a predicate.
Expand All @@ -335,12 +346,13 @@ Task<IList<TEntity>> GetAllAsync(Expression<Func<TEntity, bool>> predicate = nul
decimal Average (Expression<Func<TEntity, bool>> predicate = null, Expression<Func<TEntity, decimal>> selector = null);

/// <summary>
/// Gets the async average based on a predicate.
/// </summary>
/// <param name="predicate"></param>
/// /// <param name="selector"></param>
/// <returns>decimal</returns>
Task<decimal> AverageAsync(Expression<Func<TEntity, bool>> predicate = null, Expression<Func<TEntity, decimal>> selector = null);
/// Gets the async average based on a predicate.
/// </summary>
/// <param name="predicate"></param>
/// <param name="selector"></param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>decimal</returns>
Task<decimal> AverageAsync(Expression<Func<TEntity, bool>> predicate = null, Expression<Func<TEntity, decimal>> selector = null, CancellationToken cancellationToken = default);

/// <summary>
/// Gets the sum based on a predicate.
Expand All @@ -354,9 +366,10 @@ Task<IList<TEntity>> GetAllAsync(Expression<Func<TEntity, bool>> predicate = nul
/// Gets the async sum based on a predicate.
/// </summary>
/// <param name="predicate"></param>
/// /// <param name="selector"></param>
/// <param name="selector"></param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>decimal</returns>
Task<decimal> SumAsync (Expression<Func<TEntity, bool>> predicate = null, Expression<Func<TEntity, decimal>> selector = null);
Task<decimal> SumAsync (Expression<Func<TEntity, bool>> predicate = null, Expression<Func<TEntity, decimal>> selector = null, CancellationToken cancellationToken = default);

/// <summary>
/// Gets the Exists record based on a predicate.
Expand All @@ -368,8 +381,9 @@ Task<IList<TEntity>> GetAllAsync(Expression<Func<TEntity, bool>> predicate = nul
/// Gets the Async Exists record based on a predicate.
/// </summary>
/// <param name="selector"></param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns></returns>
Task<bool> ExistsAsync(Expression<Func<TEntity, bool>> selector = null);
Task<bool> ExistsAsync(Expression<Func<TEntity, bool>> selector = null, CancellationToken cancellationToken = default);

/// <summary>
/// Inserts a new entity synchronously.
Expand Down
5 changes: 4 additions & 1 deletion src/UnitOfWork/IUnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// </copyright>
//-----------------------------------------------------------------------

using System.Threading;

namespace Arch.EntityFrameworkCore.UnitOfWork
{
using System;
Expand Down Expand Up @@ -44,8 +46,9 @@ public interface IUnitOfWork : IDisposable
/// Asynchronously saves all changes made in this unit of work to the database.
/// </summary>
/// <param name="ensureAutoHistory"><c>True</c> if save changes ensure auto record the change history.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task{TResult}"/> that represents the asynchronous save operation. The task result contains the number of state entities written to database.</returns>
Task<int> SaveChangesAsync(bool ensureAutoHistory = false);
Task<int> SaveChangesAsync(bool ensureAutoHistory = false, CancellationToken cancellationToken = default);

/// <summary>
/// Executes the specified raw SQL command.
Expand Down
4 changes: 3 additions & 1 deletion src/UnitOfWork/IUnitOfWorkOfT.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Arch team. All rights reserved.

using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

Expand All @@ -20,7 +21,8 @@ public interface IUnitOfWork<TContext> : IUnitOfWork where TContext : DbContext
/// </summary>
/// <param name="ensureAutoHistory"><c>True</c> if save changes ensure auto record the change history.</param>
/// <param name="unitOfWorks">An optional <see cref="IUnitOfWork"/> array.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task{TResult}"/> that represents the asynchronous save operation. The task result contains the number of state entities written to database.</returns>
Task<int> SaveChangesAsync(bool ensureAutoHistory = false, params IUnitOfWork[] unitOfWorks);
Task<int> SaveChangesAsync(bool ensureAutoHistory = false, CancellationToken cancellationToken = default, params IUnitOfWork[] unitOfWorks);
}
}
Loading