Skip to content

Commit 2b63c3d

Browse files
committed
I update .NET 9
1 parent 91a04ee commit 2b63c3d

4 files changed

Lines changed: 54 additions & 12 deletions

File tree

GenericRepository/GenericRepository.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>disable</Nullable>
6+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
77
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
88
<Title>TS GenericRepository</Title>
99
<Company>Taner Saydam</Company>
@@ -14,11 +14,12 @@
1414
<PackageId>TS.EntityFrameworkCore.GenericRepository</PackageId>
1515
<AssemblyVersion></AssemblyVersion>
1616
<FileVersion></FileVersion>
17-
<Version>8.0.4</Version>
17+
<Version>9.0.1</Version>
1818
<Authors>Taner Saydam</Authors>
1919
<PackageTags>genericrepository</PackageTags>
2020
<Product>Generic Repository</Product>
2121
<RepositoryType>git</RepositoryType>
22+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2223
</PropertyGroup>
2324

2425
<ItemGroup>
@@ -29,7 +30,7 @@
2930
</ItemGroup>
3031

3132
<ItemGroup>
32-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.7" />
33+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
3334
</ItemGroup>
3435

3536
<ItemGroup>

GenericRepository/IRepository.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ public interface IRepository<TEntity>
99
IQueryable<TEntity> GetAllWithTracking();
1010
IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression);
1111
IQueryable<TEntity> WhereWithTracking(Expression<Func<TEntity, bool>> expression);
12-
12+
TEntity First(Expression<Func<TEntity, bool>> expression, bool isTrackingActive = true);
13+
TEntity FirstOrDefault(Expression<Func<TEntity, bool>> expression, bool isTrackingActive = true);
1314
Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default, bool isTrackingActive = true);
15+
Task<TEntity> FirstAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default, bool isTrackingActive = true);
1416
Task<TEntity> GetByExpressionAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
1517
Task<TEntity> GetByExpressionWithTrackingAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
1618
Task<TEntity> GetFirstAsync(CancellationToken cancellationToken = default);
@@ -29,5 +31,5 @@ public interface IRepository<TEntity>
2931
Task DeleteByExpressionAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
3032
void Delete(TEntity entity);
3133
void DeleteRange(ICollection<TEntity> entities);
32-
33-
}
34+
IQueryable<KeyValuePair<bool, int>> CountBy(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
35+
}

GenericRepository/Repository.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,39 @@ public void AddRange(ICollection<TEntity> entities)
149149
{
150150
Entity.AddRange(entities);
151151
}
152+
153+
public TEntity FirstOrDefault(Expression<Func<TEntity, bool>> expression, bool isTrackingActive = true)
154+
{
155+
if (isTrackingActive)
156+
{
157+
return Entity.FirstOrDefault(expression);
158+
}
159+
160+
return Entity.AsNoTracking().FirstOrDefault(expression);
161+
}
162+
163+
public IQueryable<KeyValuePair<bool, int>> CountBy(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default)
164+
{
165+
return Entity.CountBy(expression);
166+
}
167+
168+
public TEntity First(Expression<Func<TEntity, bool>> expression, bool isTrackingActive = true)
169+
{
170+
if (isTrackingActive)
171+
{
172+
return Entity.First(expression);
173+
}
174+
175+
return Entity.AsNoTracking().First(expression);
176+
}
177+
178+
public async Task<TEntity> FirstAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default, bool isTrackingActive = true)
179+
{
180+
if (isTrackingActive)
181+
{
182+
return await Entity.FirstAsync(expression, cancellationToken);
183+
}
184+
185+
return await Entity.AsNoTracking().FirstAsync(expression, cancellationToken);
186+
}
152187
}

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dependency
22

3-
This library was created by .Net 8.0
3+
This library was created by .Net 9.0
44

55
## Install
66
```bash
@@ -69,9 +69,12 @@ public interface IRepository<TEntity>
6969
{
7070
IQueryable<TEntity> GetAll();
7171
IQueryable<TEntity> GetAllWithTracking();
72-
IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression);
72+
IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression);
7373
IQueryable<TEntity> WhereWithTracking(Expression<Func<TEntity, bool>> expression);
74+
TEntity First(Expression<Func<TEntity, bool>> expression, bool isTrackingActive = true);
75+
TEntity FirstOrDefault(Expression<Func<TEntity, bool>> expression, bool isTrackingActive = true);
7476
Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default, bool isTrackingActive = true);
77+
Task<TEntity> FirstAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default, bool isTrackingActive = true);
7578
Task<TEntity> GetByExpressionAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
7679
Task<TEntity> GetByExpressionWithTrackingAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
7780
Task<TEntity> GetFirstAsync(CancellationToken cancellationToken = default);
@@ -83,12 +86,13 @@ public interface IRepository<TEntity>
8386
Task AddAsync(TEntity entity, CancellationToken cancellationToken = default);
8487
void Add(TEntity entity);
8588
Task AddRangeAsync(ICollection<TEntity> entities, CancellationToken cancellationToken = default);
89+
void AddRange(ICollection<TEntity> entities);
8690
void Update(TEntity entity);
8791
void UpdateRange(ICollection<TEntity> entities);
8892
Task DeleteByIdAsync(string id);
89-
Task DeleteByExpressionAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
93+
Task DeleteByExpressionAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
9094
void Delete(TEntity entity);
9195
void DeleteRange(ICollection<TEntity> entities);
92-
96+
IQueryable<KeyValuePair<bool, int>> CountBy(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default);
9397
}
9498
```

0 commit comments

Comments
 (0)