Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit ea4407c

Browse files
committed
WIP: Aggiunti nuovi metodi EFCore
1 parent 2629c51 commit ea4407c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/NET6CustomLibrary/EFCore/Infrastructure/Interfaces/IDatabaseRepository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
public interface IDatabaseRepository<TEntity, TKey> : IDatabase<TEntity, TKey> where TEntity : class, IEntity<TKey>, new()
44
{
5+
Task<List<TEntity>> GetOrderByIdAscendingAsync();
6+
Task<List<TEntity>> GetOrderByIdDescendingAsync();
7+
Task<int> GetCountAsync();
58
}

src/NET6CustomLibrary/EFCore/Infrastructure/Repository/DatabaseRepository.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,26 @@
55
public DatabaseRepository(DbContext dbContext) : base(dbContext)
66
{
77
}
8+
9+
public async Task<int> GetCountAsync()
10+
{
11+
return await DbContext.Set<TEntity>()
12+
.CountAsync();
13+
}
14+
15+
public async Task<List<TEntity>> GetOrderByIdAscendingAsync()
16+
{
17+
return await DbContext.Set<TEntity>()
18+
.OrderBy(x => x.Id)
19+
.AsNoTracking()
20+
.ToListAsync();
21+
}
22+
23+
public async Task<List<TEntity>> GetOrderByIdDescendingAsync()
24+
{
25+
return await DbContext.Set<TEntity>()
26+
.OrderByDescending(x => x.Id)
27+
.AsNoTracking()
28+
.ToListAsync();
29+
}
830
}

0 commit comments

Comments
 (0)