Skip to content

Commit 1e86c8c

Browse files
authored
Added new methods in WriteGenericRepository (#96)
1 parent 4de3af1 commit 1e86c8c

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

source/EasyWay.EntityFrameworkCore/IWriteGenericRepository.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace EasyWay
1+
using System.Linq.Expressions;
2+
3+
namespace EasyWay
24
{
35
public interface IWriteGenericRepository<TAggregateRoot>
46
where TAggregateRoot : AggregateRoot
@@ -12,5 +14,13 @@ public interface IWriteGenericRepository<TAggregateRoot>
1214
Task Remove(TAggregateRoot aggregateRoot);
1315

1416
Task Remove(IEnumerable<TAggregateRoot> aggregateRoots);
17+
18+
Task Any();
19+
20+
Task Any(Expression<Func<TAggregateRoot, bool>> predicate);
21+
22+
Task<int> Count();
23+
24+
Task<int> Count(Expression<Func<TAggregateRoot, bool>> predicate);
1525
}
1626
}

source/EasyWay.EntityFrameworkCore/Internals/Repositories/WriteGenericRepository.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.EntityFrameworkCore;
2+
using System.Linq.Expressions;
23

34
namespace EasyWay.Internals.Repositories
45
{
@@ -22,6 +23,26 @@ public Task Add(IEnumerable<TAggregateRoot> aggregateRoots)
2223
return _aggregateRoots.AddRangeAsync(aggregateRoots);
2324
}
2425

26+
public Task Any()
27+
{
28+
return _aggregateRoots.AnyAsync();
29+
}
30+
31+
public Task Any(Expression<Func<TAggregateRoot, bool>> predicate)
32+
{
33+
return _aggregateRoots.AnyAsync(predicate);
34+
}
35+
36+
public Task<int> Count()
37+
{
38+
return _aggregateRoots.CountAsync();
39+
}
40+
41+
public Task<int> Count(Expression<Func<TAggregateRoot, bool>> predicate)
42+
{
43+
return _aggregateRoots.CountAsync(predicate);
44+
}
45+
2546
public Task<TAggregateRoot?> Get(Guid id)
2647
{
2748
return _aggregateRoots.FindAsync(id).AsTask();

0 commit comments

Comments
 (0)