Skip to content

Commit 56961bb

Browse files
committed
Aggiornata documentazione
1 parent f84eabb commit 56961bb

File tree

2 files changed

+38
-46
lines changed

2 files changed

+38
-46
lines changed
Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,65 @@
11
namespace ClassLibrary.EFCore.Interfaces;
22

3-
/// <summary>
4-
/// Repository interface for entity operations.
5-
/// </summary>
6-
/// <typeparam name="TEntity">The type of the entity.</typeparam>
7-
/// <typeparam name="TKey">The type of the entity's primary key.</typeparam>
83
public interface IRepository<TEntity, TKey> where TEntity : class, IEntity<TKey>, new()
94
{
105
/// <summary>
11-
/// Asynchronously gets all entities.
6+
/// Retrieves all entities asynchronously.
127
/// </summary>
13-
/// <returns>A task that represents the asynchronous operation. The task result contains a list of entities.</returns>
8+
/// <returns>A task that represents the asynchronous operation. The task result contains a list of all entities.</returns>
149
Task<List<TEntity>> GetAllAsync();
1510

1611
/// <summary>
17-
/// Asynchronously gets all entities that satisfy the given predicate.
12+
/// Retrieves all entities that match the specified predicate asynchronously.
1813
/// </summary>
19-
/// <param name="predicate">A function to test each element for a condition.</param>
20-
/// <returns>A task that represents the asynchronous operation. The task result contains a list of entities that satisfy the condition.</returns>
14+
/// <param name="predicate">The predicate to filter entities.</param>
15+
/// <returns>A task that represents the asynchronous operation. The task result contains a list of entities that match the predicate.</returns>
2116
Task<List<TEntity>> GetAllEntitiesAsync(Func<TEntity, bool> predicate);
2217

2318
/// <summary>
24-
/// Asynchronously gets the entity by its id.
19+
/// Retrieves an entity by its identifier asynchronously.
2520
/// </summary>
26-
/// <param name="id">The id of the entity.</param>
27-
/// <returns>A task that represents the asynchronous operation. The task result contains the entity if found, null otherwise.</returns>
21+
/// <param name="id">The identifier of the entity.</param>
22+
/// <returns>A task that represents the asynchronous operation. The task result contains the entity if found; otherwise, null.</returns>
2823
Task<TEntity?> GetByIdAsync(TKey id);
2924

3025
/// <summary>
31-
/// Asynchronously creates a new entity.
26+
/// Creates a new entity asynchronously.
3227
/// </summary>
3328
/// <param name="entity">The entity to create.</param>
3429
/// <returns>A task that represents the asynchronous operation.</returns>
3530
Task CreateAsync(TEntity entity);
3631

3732
/// <summary>
38-
/// Asynchronously updates an existing entity.
33+
/// Updates an existing entity asynchronously.
3934
/// </summary>
4035
/// <param name="entity">The entity to update.</param>
4136
/// <returns>A task that represents the asynchronous operation.</returns>
4237
Task UpdateAsync(TEntity entity);
4338

4439
/// <summary>
45-
/// Asynchronously deletes an existing entity.
40+
/// Deletes an existing entity asynchronously.
4641
/// </summary>
4742
/// <param name="entity">The entity to delete.</param>
4843
/// <returns>A task that represents the asynchronous operation.</returns>
4944
Task DeleteAsync(TEntity entity);
5045

5146
/// <summary>
52-
/// Asynchronously deletes an entity by its id.
47+
/// Deletes an entity by its identifier asynchronously.
5348
/// </summary>
54-
/// <param name="id">The id of the entity to delete.</param>
49+
/// <param name="id">The identifier of the entity to delete.</param>
5550
/// <returns>A task that represents the asynchronous operation.</returns>
5651
Task DeleteByIdAsync(TKey id);
5752

5853
/// <summary>
59-
/// Asynchronously gets a paginated list of entities that satisfy the given conditions.
54+
/// Retrieves a paginated list of entities that match the specified conditions asynchronously.
6055
/// </summary>
6156
/// <param name="includes">A function to include related entities.</param>
62-
/// <param name="conditionWhere">A function to test each element for a condition.</param>
63-
/// <param name="orderBy">A function to order the elements.</param>
64-
/// <param name="ascending">A boolean indicating whether the order is ascending.</param>
57+
/// <param name="conditionWhere">The condition to filter entities.</param>
58+
/// <param name="orderBy">The expression to order entities.</param>
59+
/// <param name="ascending">A value indicating whether to order entities in ascending order.</param>
6560
/// <param name="pageIndex">The index of the page to retrieve.</param>
6661
/// <param name="pageSize">The size of the page to retrieve.</param>
67-
/// <returns>A task that represents the asynchronous operation. The task result contains a list of entities that satisfy the conditions.</returns>
62+
/// <returns>A task that represents the asynchronous operation. The task result contains a list of paginated entities.</returns>
6863
public Task<List<TEntity>> GetPaginatedAsync(Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includes,
6964
Expression<Func<TEntity, bool>> conditionWhere, Expression<Func<TEntity, dynamic>> orderBy, bool ascending, int pageIndex, int pageSize);
7065
}

src/ClassLibrary.EFCore/Repository.cs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,32 @@
22

33
namespace 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>
105
public 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

Comments
 (0)