Skip to content

Commit 1b64033

Browse files
author
Taner Saydam
committed
I added Count methods
1 parent 2b63c3d commit 1b64033

5 files changed

Lines changed: 33 additions & 10 deletions

File tree

GenericRepository/GenericRepository.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<Description>This is a Generic Repository for Entity Framework Core with .NET Core</Description>
1111
<PackageIcon>logo.jpg</PackageIcon>
1212
<PackageReadmeFile>README.md</PackageReadmeFile>
13-
<RepositoryUrl>https://github.com/TanerSaydam/TS.GenericRepository.NuGet</RepositoryUrl>
13+
<RepositoryUrl>https://github.com/TanerSaydam/TS.GenericRepository.NuGet.git</RepositoryUrl>
1414
<PackageId>TS.EntityFrameworkCore.GenericRepository</PackageId>
1515
<AssemblyVersion></AssemblyVersion>
1616
<FileVersion></FileVersion>
17-
<Version>9.0.1</Version>
17+
<Version>9.0.3</Version>
1818
<Authors>Taner Saydam</Authors>
1919
<PackageTags>genericrepository</PackageTags>
2020
<Product>Generic Repository</Product>

GenericRepository/IRepository.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ public interface IRepository<TEntity>
3232
void Delete(TEntity entity);
3333
void DeleteRange(ICollection<TEntity> entities);
3434
IQueryable<KeyValuePair<bool, int>> CountBy(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
35+
int Count();
36+
int Count(Expression<Func<TEntity, bool>> expression);
37+
Task<int> CountAsync(CancellationToken cancellationToken = default);
38+
Task<int> CountAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
3539
}

GenericRepository/Repository.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using Microsoft.EntityFrameworkCore;
2-
using System.Linq.Expressions;
1+
using System.Linq.Expressions;
2+
using Microsoft.EntityFrameworkCore;
33

44
namespace GenericRepository;
55

@@ -184,4 +184,24 @@ public async Task<TEntity> FirstAsync(Expression<Func<TEntity, bool>> expression
184184

185185
return await Entity.AsNoTracking().FirstAsync(expression, cancellationToken);
186186
}
187+
188+
public int Count()
189+
{
190+
return Entity.Count();
191+
}
192+
193+
public int Count(Expression<Func<TEntity, bool>> expression)
194+
{
195+
return Entity.Count(expression);
196+
}
197+
198+
public async Task<int> CountAsync(CancellationToken cancellationToken = default)
199+
{
200+
return await Entity.CountAsync(cancellationToken);
201+
}
202+
203+
public async Task<int> CountAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default)
204+
{
205+
return await Entity.CountAsync(expression, cancellationToken);
206+
}
187207
}

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public interface IRepository<TEntity>
9393
Task DeleteByExpressionAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
9494
void Delete(TEntity entity);
9595
void DeleteRange(ICollection<TEntity> entities);
96-
IQueryable<KeyValuePair<bool, int>> CountBy(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
96+
IQueryable<KeyValuePair<bool, int>> CountBy(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
97+
int Count();
98+
int Count(Expression<Func<TEntity, bool>> expression);
99+
Task<int> CountAsync(CancellationToken cancellationToken = default);
100+
Task<int> CountAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
97101
}
98102
```

TS.GenericRepository.sln

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ VisualStudioVersion = 17.5.33530.505
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenericRepository", "GenericRepository\GenericRepository.csproj", "{13D33905-2354-4849-A3D5-8595369125EB}"
77
EndProject
8-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{03080160-C5D6-4B85-B9C8-DB4CD4D9DD0C}"
9-
ProjectSection(SolutionItems) = preProject
10-
README.md = README.md
11-
EndProjectSection
12-
EndProject
138
Global
149
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1510
Debug|Any CPU = Debug|Any CPU

0 commit comments

Comments
 (0)