using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Query; using xModels.Base; using xModels.Dtos; namespace xDataService.Interfaces { public interface IXBaseRepository : IDisposable { } /// /// Base Repository Pattern Contracts in XDashboard's Data Service ... /// use for Data Manipulation ... /// /// /// public interface IXBaseRepository : IXBaseRepository where T : XBaseEntity { // #region Add ... /// /// add a new Entity ... /// /// /// /// /// Task AddAsync( T item, bool saveChanges = true, CancellationToken cancellationToken = default ); /// /// add or update an Entity (add if not exists/update if exists) ... /// /// /// /// /// Task AddOrUpdateAsync( T item, bool saveChanges = true, CancellationToken cancellationToken = default ); /// /// add a range of new Entities ... /// /// /// /// /// Task AddRangeAsync( IEnumerable items, bool saveChanges = true, CancellationToken cancellationToken = default ); #endregion // #region Update ... /// /// Update an Entity values ... /// /// /// /// /// /// Task UpdateAsync( TKey id, T item, bool saveChanges = true, CancellationToken cancellationToken = default ); /// /// Update a range of Entities ... /// /// /// /// /// Task UpdateRangeAsync( IEnumerable items, bool saveChanges = true, CancellationToken cancellationToken = default ); #endregion // #region Remove ... /// /// remove an Entity by it's Id ... /// /// /// /// /// /// Task RemoveAsync( TKey id, bool softDelete = true, bool saveChanges = true, CancellationToken cancellationToken = default ); /// /// remove an Entity ... /// /// /// /// /// /// Task RemoveAsync( T item, bool softDelete = true, bool saveChanges = true, CancellationToken cancellationToken = default ); /// /// remove a range of exists Entities ... /// /// /// /// /// /// Task RemoveRangeAsync( IEnumerable items, bool softDelete = true, bool saveChanges = true, CancellationToken cancellationToken = default ); #endregion // #region Count ... /// /// count all exists Entities ... /// /// /// /// Task CountAsync( bool ignoreSoftDeleteds = true, CancellationToken cancellationToken = default ); /// /// count all exists Entities Pages by providing page size ... /// /// /// /// /// /// Task PagesCountAsync( int pageSize, int? totalItems = null, bool ignoreSoftDeleteds = true, CancellationToken cancellationToken = default ); #endregion // #region Retrieve ... /// /// retrieve whole items as queryable ... /// /// a flag for Tracking behaviour /// an Expression for Filter Items ... /// an Order Builder expression for Ordering Query ... /// an Include Builder expression for Including Navigation Properties ... /// IQueryable AsQueryable( bool asNoTracking = true, Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, Func, IIncludableQueryable> includeBuilder = null ); /// /// retrieve an Entity by it's Id ... /// /// /// /// /// /// Task GetAsync( TKey id, bool ignoreSoftDeleteds = true, Func, IIncludableQueryable> includeBuilder = null, CancellationToken cancellationToken = default ); /// /// retrieve all exists Entities ... /// /// /// /// /// /// Task> GetAllAsync( bool ignoreSoftDeleteds = true, Func, IOrderedQueryable> orderBuilder = null, Func, IIncludableQueryable> includeBuilder = null, CancellationToken cancellationToken = default ); /// /// retrieve all exists Entities /// as Async Enumerable ... /// /// /// /// /// IAsyncEnumerable GetAllAsAsyncEnumerable( bool ignoreSoftDeleteds = true, Func, IOrderedQueryable> orderBuilder = null, Func, IIncludableQueryable> includeBuilder = null ); /// /// find an Entity by providing a Conditional Expression ... /// /// /// /// /// /// Task FindOneAsync( Expression> predicate, bool ignoreSoftDeleteds = true, Func, IIncludableQueryable> includeBuilder = null, CancellationToken cancellationToken = default ); /// /// find a collection of Entities by proving a Conditional Expression ... /// /// /// /// /// /// /// Task> FindManyAsync( Expression> predicate, bool ignoreSoftDeleteds = true, Func, IOrderedQueryable> orderBuilder = null, Func, IIncludableQueryable> includeBuilder = null, CancellationToken cancellationToken = default ); /// /// retrieve Entities based on XQuery Pagination structure ... /// /// /// /// /// /// /// /// Task> QueryAsync( XQuery query, bool ignoreSoftDeleteds = true, Expression> predicate = null, Func, IOrderedQueryable> orderBuilder = null, Func, IIncludableQueryable> includeBuilder = null, CancellationToken cancellationToken = default ); #endregion // #region Exists ... /// /// Check an Entity exists or not ... /// /// /// /// /// Task IsExistsAsync( TKey id, bool ignoreSoftDeleteds = true, CancellationToken cancellationToken = default ); #endregion // #region Unit Of Work ... /// /// Save all unsaved Transactions on DbContext ... /// used fo Unit Of Works Design Pattern ... /// /// /// Task SaveChangesAsync( CancellationToken cancellationToken = default ); #endregion // #region Key ... /// /// Retrieve Key of Entity ... /// /// /// TKey GetKey(T item); /// /// Set Key of Entity ... /// /// /// void SetKey( ref T item, TKey id ); /// /// Handle Checking Key ... /// /// /// /// Task HandleKeyAsync( T item, CancellationToken cancellationToken = default ); #endregion // #region Detach ... /// /// Detach an Entity ... /// /// void Detach(T item); /// /// Detach an Enumerable of Entities ... /// /// void Detach(IEnumerable items); /// /// Detach a Query Result of Entity ... /// /// void Detach(XQueryResult query); #endregion } }