| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Threading.Tasks;
- using Abp.Domain.Entities;
- using Abp.Domain.Uow;
- namespace Abp.Domain.Repositories
- {
- /// <summary>
- /// This interface is implemented by all repositories to ensure implementation of fixed methods.
- /// </summary>
- /// <typeparam name="TEntity">Main Entity type this repository works on</typeparam>
- /// <typeparam name="TPrimaryKey">Primary key type of the entity</typeparam>
- public interface IRepository<TEntity, TPrimaryKey> : IRepository where TEntity : class, IEntity<TPrimaryKey>
- {
- #region Select/Get/Query
- /// <summary>
- /// Used to get a IQueryable that is used to retrieve entities from entire table.
- /// </summary>
- /// <returns>IQueryable to be used to select entities from database</returns>
- IQueryable<TEntity> GetAll();
- /// <summary>
- /// Used to get a IQueryable that is used to retrieve entities from entire table.
- /// One or more
- /// </summary>
- /// <param name="propertySelectors">A list of include expressions.</param>
- /// <returns>IQueryable to be used to select entities from database</returns>
- IQueryable<TEntity> GetAllIncluding(params Expression<Func<TEntity, object>>[] propertySelectors);
- /// <summary>
- /// Used to get all entities.
- /// </summary>
- /// <returns>List of all entities</returns>
- List<TEntity> GetAllList();
- /// <summary>
- /// Used to get all entities.
- /// </summary>
- /// <returns>List of all entities</returns>
- Task<List<TEntity>> GetAllListAsync();
- /// <summary>
- /// Used to get all entities based on given <paramref name="predicate"/>.
- /// </summary>
- /// <param name="predicate">A condition to filter entities</param>
- /// <returns>List of all entities</returns>
- List<TEntity> GetAllList(Expression<Func<TEntity, bool>> predicate);
- /// <summary>
- /// Used to get all entities based on given <paramref name="predicate"/>.
- /// </summary>
- /// <param name="predicate">A condition to filter entities</param>
- /// <returns>List of all entities</returns>
- Task<List<TEntity>> GetAllListAsync(Expression<Func<TEntity, bool>> predicate);
- /// <summary>
- /// Used to run a query over entire entities.
- /// <see cref="UnitOfWorkAttribute"/> attribute is not always necessary (as opposite to <see cref="GetAll"/>)
- /// if <paramref name="queryMethod"/> finishes IQueryable with ToList, FirstOrDefault etc..
- /// </summary>
- /// <typeparam name="T">Type of return value of this method</typeparam>
- /// <param name="queryMethod">This method is used to query over entities</param>
- /// <returns>Query result</returns>
- T Query<T>(Func<IQueryable<TEntity>, T> queryMethod);
- /// <summary>
- /// Gets an entity with given primary key.
- /// </summary>
- /// <param name="id">Primary key of the entity to get</param>
- /// <returns>Entity</returns>
- TEntity Get(TPrimaryKey id);
- /// <summary>
- /// Gets an entity with given primary key.
- /// </summary>
- /// <param name="id">Primary key of the entity to get</param>
- /// <returns>Entity</returns>
- Task<TEntity> GetAsync(TPrimaryKey id);
- /// <summary>
- /// Gets exactly one entity with given predicate.
- /// Throws exception if no entity or more than one entity.
- /// </summary>
- /// <param name="predicate">Entity</param>
- TEntity Single(Expression<Func<TEntity, bool>> predicate);
- /// <summary>
- /// Gets exactly one entity with given predicate.
- /// Throws exception if no entity or more than one entity.
- /// </summary>
- /// <param name="predicate">Entity</param>
- Task<TEntity> SingleAsync(Expression<Func<TEntity, bool>> predicate);
- /// <summary>
- /// Gets an entity with given primary key or null if not found.
- /// </summary>
- /// <param name="id">Primary key of the entity to get</param>
- /// <returns>Entity or null</returns>
- TEntity FirstOrDefault(TPrimaryKey id);
- /// <summary>
- /// Gets an entity with given primary key or null if not found.
- /// </summary>
- /// <param name="id">Primary key of the entity to get</param>
- /// <returns>Entity or null</returns>
- Task<TEntity> FirstOrDefaultAsync(TPrimaryKey id);
- /// <summary>
- /// Gets an entity with given given predicate or null if not found.
- /// </summary>
- /// <param name="predicate">Predicate to filter entities</param>
- TEntity FirstOrDefault(Expression<Func<TEntity, bool>> predicate);
- /// <summary>
- /// Gets an entity with given given predicate or null if not found.
- /// </summary>
- /// <param name="predicate">Predicate to filter entities</param>
- Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate);
- /// <summary>
- /// Creates an entity with given primary key without database access.
- /// </summary>
- /// <param name="id">Primary key of the entity to load</param>
- /// <returns>Entity</returns>
- TEntity Load(TPrimaryKey id);
- #endregion
- #region Insert
- /// <summary>
- /// Inserts a new entity.
- /// </summary>
- /// <param name="entity">Inserted entity</param>
- TEntity Insert(TEntity entity);
- /// <summary>
- /// Inserts a new entity.
- /// </summary>
- /// <param name="entity">Inserted entity</param>
- Task<TEntity> InsertAsync(TEntity entity);
- /// <summary>
- /// Inserts a new entity and gets it's Id.
- /// It may require to save current unit of work
- /// to be able to retrieve id.
- /// </summary>
- /// <param name="entity">Entity</param>
- /// <returns>Id of the entity</returns>
- TPrimaryKey InsertAndGetId(TEntity entity);
- /// <summary>
- /// Inserts a new entity and gets it's Id.
- /// It may require to save current unit of work
- /// to be able to retrieve id.
- /// </summary>
- /// <param name="entity">Entity</param>
- /// <returns>Id of the entity</returns>
- Task<TPrimaryKey> InsertAndGetIdAsync(TEntity entity);
- /// <summary>
- /// Inserts or updates given entity depending on Id's value.
- /// </summary>
- /// <param name="entity">Entity</param>
- TEntity InsertOrUpdate(TEntity entity);
- /// <summary>
- /// Inserts or updates given entity depending on Id's value.
- /// </summary>
- /// <param name="entity">Entity</param>
- Task<TEntity> InsertOrUpdateAsync(TEntity entity);
- /// <summary>
- /// Inserts or updates given entity depending on Id's value.
- /// Also returns Id of the entity.
- /// It may require to save current unit of work
- /// to be able to retrieve id.
- /// </summary>
- /// <param name="entity">Entity</param>
- /// <returns>Id of the entity</returns>
- TPrimaryKey InsertOrUpdateAndGetId(TEntity entity);
- /// <summary>
- /// Inserts or updates given entity depending on Id's value.
- /// Also returns Id of the entity.
- /// It may require to save current unit of work
- /// to be able to retrieve id.
- /// </summary>
- /// <param name="entity">Entity</param>
- /// <returns>Id of the entity</returns>
- Task<TPrimaryKey> InsertOrUpdateAndGetIdAsync(TEntity entity);
- #endregion
- #region Update
- /// <summary>
- /// Updates an existing entity.
- /// </summary>
- /// <param name="entity">Entity</param>
- TEntity Update(TEntity entity);
- /// <summary>
- /// Updates an existing entity.
- /// </summary>
- /// <param name="entity">Entity</param>
- Task<TEntity> UpdateAsync(TEntity entity);
- /// <summary>
- /// Updates an existing entity.
- /// </summary>
- /// <param name="id">Id of the entity</param>
- /// <param name="updateAction">Action that can be used to change values of the entity</param>
- /// <returns>Updated entity</returns>
- TEntity Update(TPrimaryKey id, Action<TEntity> updateAction);
- /// <summary>
- /// Updates an existing entity.
- /// </summary>
- /// <param name="id">Id of the entity</param>
- /// <param name="updateAction">Action that can be used to change values of the entity</param>
- /// <returns>Updated entity</returns>
- Task<TEntity> UpdateAsync(TPrimaryKey id, Func<TEntity, Task> updateAction);
- #endregion
- #region Delete
- /// <summary>
- /// Deletes an entity.
- /// </summary>
- /// <param name="entity">Entity to be deleted</param>
- void Delete(TEntity entity);
- /// <summary>
- /// Deletes an entity.
- /// </summary>
- /// <param name="entity">Entity to be deleted</param>
- Task DeleteAsync(TEntity entity);
- /// <summary>
- /// Deletes an entity by primary key.
- /// </summary>
- /// <param name="id">Primary key of the entity</param>
- void Delete(TPrimaryKey id);
- /// <summary>
- /// Deletes an entity by primary key.
- /// </summary>
- /// <param name="id">Primary key of the entity</param>
- Task DeleteAsync(TPrimaryKey id);
- /// <summary>
- /// Deletes many entities by function.
- /// Notice that: All entities fits to given predicate are retrieved and deleted.
- /// This may cause major performance problems if there are too many entities with
- /// given predicate.
- /// </summary>
- /// <param name="predicate">A condition to filter entities</param>
- void Delete(Expression<Func<TEntity, bool>> predicate);
- /// <summary>
- /// Deletes many entities by function.
- /// Notice that: All entities fits to given predicate are retrieved and deleted.
- /// This may cause major performance problems if there are too many entities with
- /// given predicate.
- /// </summary>
- /// <param name="predicate">A condition to filter entities</param>
- Task DeleteAsync(Expression<Func<TEntity, bool>> predicate);
- #endregion
- #region Aggregates
- /// <summary>
- /// Gets count of all entities in this repository.
- /// </summary>
- /// <returns>Count of entities</returns>
- int Count();
- /// <summary>
- /// Gets count of all entities in this repository.
- /// </summary>
- /// <returns>Count of entities</returns>
- Task<int> CountAsync();
- /// <summary>
- /// Gets count of all entities in this repository based on given <paramref name="predicate"/>.
- /// </summary>
- /// <param name="predicate">A method to filter count</param>
- /// <returns>Count of entities</returns>
- int Count(Expression<Func<TEntity, bool>> predicate);
- /// <summary>
- /// Gets count of all entities in this repository based on given <paramref name="predicate"/>.
- /// </summary>
- /// <param name="predicate">A method to filter count</param>
- /// <returns>Count of entities</returns>
- Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate);
- /// <summary>
- /// Gets count of all entities in this repository (use if expected return value is greather than <see cref="int.MaxValue"/>.
- /// </summary>
- /// <returns>Count of entities</returns>
- long LongCount();
- /// <summary>
- /// Gets count of all entities in this repository (use if expected return value is greather than <see cref="int.MaxValue"/>.
- /// </summary>
- /// <returns>Count of entities</returns>
- Task<long> LongCountAsync();
- /// <summary>
- /// Gets count of all entities in this repository based on given <paramref name="predicate"/>
- /// (use this overload if expected return value is greather than <see cref="int.MaxValue"/>).
- /// </summary>
- /// <param name="predicate">A method to filter count</param>
- /// <returns>Count of entities</returns>
- long LongCount(Expression<Func<TEntity, bool>> predicate);
- /// <summary>
- /// Gets count of all entities in this repository based on given <paramref name="predicate"/>
- /// (use this overload if expected return value is greather than <see cref="int.MaxValue"/>).
- /// </summary>
- /// <param name="predicate">A method to filter count</param>
- /// <returns>Count of entities</returns>
- Task<long> LongCountAsync(Expression<Func<TEntity, bool>> predicate);
- #endregion
- }
- }
|