22
33namespace ClassLibrary . EFCore ;
44
5- /// <summary>
6- /// Repository class for Entity Framework Core operations.
7- /// </summary>
8- /// <typeparam name="TEntity">The type of the entity.</typeparam>
9- /// <typeparam name="TKey">The type of the entity's primary key.</typeparam>
105public class Repository < TEntity , TKey > ( DbContext dbContext ) : IRepository < TEntity , TKey > where TEntity : class , IEntity < TKey > , new ( )
116{
127 /// <summary>
13- /// Gets the DbContext .
8+ /// Gets the database context .
149 /// </summary>
1510 public DbContext DbContext { get ; } = dbContext ?? throw new ArgumentNullException ( nameof ( dbContext ) ) ;
1611
1712 /// <summary>
18- /// Asynchronously gets all entities.
13+ /// Retrieves all entities asynchronously .
1914 /// </summary>
20- /// <returns>A task that represents the asynchronous operation. The task result contains a list of entities.</returns>
15+ /// <returns>A task that represents the asynchronous operation. The task result contains a list of all entities.</returns>
2116 public async Task < List < TEntity > > GetAllAsync ( )
2217 => await DbContext . Set < TEntity > ( ) . AsNoTracking ( ) . ToListAsync ( ) ;
2318
2419 /// <summary>
25- /// Asynchronously gets all entities that satisfy the given predicate.
20+ /// Retrieves all entities that match the specified predicate asynchronously .
2621 /// </summary>
27- /// <param name="predicate">A function to test each element for a condition .</param>
28- /// <returns>A task that represents the asynchronous operation. The task result contains a list of entities that satisfy the condition .</returns>
22+ /// <param name="predicate">The predicate to filter entities .</param>
23+ /// <returns>A task that represents the asynchronous operation. The task result contains a list of entities that match the predicate .</returns>
2924 public async Task < List < TEntity > > GetAllEntitiesAsync ( Func < TEntity , bool > predicate )
3025 => await Task . FromResult ( DbContext . Set < TEntity > ( ) . AsNoTracking ( ) . Where ( predicate ) . ToList ( ) ) ;
3126
3227 /// <summary>
33- /// Asynchronously gets an entity by its id .
28+ /// Retrieves an entity by its identifier asynchronously .
3429 /// </summary>
35- /// <param name="id">The id of the entity.</param>
30+ /// <param name="id">The identifier of the entity.</param>
3631 /// <returns>A task that represents the asynchronous operation. The task result contains the entity if found; otherwise, null.</returns>
3732 public async Task < TEntity ? > GetByIdAsync ( TKey id )
3833 {
@@ -49,7 +44,7 @@ public async Task<List<TEntity>> GetAllEntitiesAsync(Func<TEntity, bool> predica
4944 }
5045
5146 /// <summary>
52- /// Asynchronously creates a new entity.
47+ /// Creates a new entity asynchronously .
5348 /// </summary>
5449 /// <param name="entity">The entity to create.</param>
5550 /// <returns>A task that represents the asynchronous operation.</returns>
@@ -63,7 +58,7 @@ public async Task CreateAsync(TEntity entity)
6358 }
6459
6560 /// <summary>
66- /// Asynchronously updates an existing entity.
61+ /// Updates an existing entity asynchronously .
6762 /// </summary>
6863 /// <param name="entity">The entity to update.</param>
6964 /// <returns>A task that represents the asynchronous operation.</returns>
@@ -77,7 +72,7 @@ public async Task UpdateAsync(TEntity entity)
7772 }
7873
7974 /// <summary>
80- /// Asynchronously deletes an existing entity.
75+ /// Deletes an existing entity asynchronously .
8176 /// </summary>
8277 /// <param name="entity">The entity to delete.</param>
8378 /// <returns>A task that represents the asynchronous operation.</returns>
@@ -89,9 +84,9 @@ public async Task DeleteAsync(TEntity entity)
8984 }
9085
9186 /// <summary>
92- /// Asynchronously deletes an entity by its id .
87+ /// Deletes an entity by its identifier asynchronously .
9388 /// </summary>
94- /// <param name="id">The id of the entity to delete.</param>
89+ /// <param name="id">The identifier of the entity to delete.</param>
9590 /// <returns>A task that represents the asynchronous operation.</returns>
9691 public async Task DeleteByIdAsync ( TKey id )
9792 {
@@ -103,12 +98,12 @@ public async Task DeleteByIdAsync(TKey id)
10398 }
10499
105100 /// <summary>
106- /// Asynchronously gets a paginated list of entities.
101+ /// Retrieves a paginated list of entities that match the specified conditions asynchronously .
107102 /// </summary>
108103 /// <param name="includes">A function to include related entities.</param>
109- /// <param name="conditionWhere">A condition to filter the entities.</param>
110- /// <param name="orderBy">A function to order the entities.</param>
111- /// <param name="ascending">A boolean indicating whether the order is ascending.</param>
104+ /// <param name="conditionWhere">The condition to filter entities.</param>
105+ /// <param name="orderBy">The expression to order entities.</param>
106+ /// <param name="ascending">A value indicating whether to order entities in ascending order .</param>
112107 /// <param name="pageIndex">The index of the page to retrieve.</param>
113108 /// <param name="pageSize">The size of the page to retrieve.</param>
114109 /// <returns>A task that represents the asynchronous operation. The task result contains a list of paginated entities.</returns>
@@ -117,6 +112,8 @@ public Task<List<TEntity>> GetPaginatedAsync(Func<IQueryable<TEntity>, IIncludab
117112 {
118113 IQueryable < TEntity > query = DbContext . Set < TEntity > ( ) ;
119114
115+ query = query . AsNoTracking ( ) ;
116+
120117 if ( includes != null )
121118 {
122119 query = includes ( query ) ;
@@ -132,6 +129,6 @@ public Task<List<TEntity>> GetPaginatedAsync(Func<IQueryable<TEntity>, IIncludab
132129 query = query . OrderedByAscending ( orderBy , ascending ) ;
133130 }
134131
135- return query . Page ( pageIndex , pageSize ) . AsNoTracking ( ) . ToListAsync ( ) ;
132+ return query . Page ( pageIndex , pageSize ) . ToListAsync ( ) ;
136133 }
137134}
0 commit comments