Skip to content

Commit 91a04ee

Browse files
committed
AddRange methods added
1 parent 1cd917d commit 91a04ee

5 files changed

Lines changed: 11 additions & 160 deletions

File tree

GenericRepository/GenericRepository.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
88
<Title>TS GenericRepository</Title>
99
<Company>Taner Saydam</Company>
10-
<Description>This is a Generic Repository Service for Entity Framework Core with .NET Core</Description>
10+
<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/GenericRepositoryNugetPackage</RepositoryUrl>
13+
<RepositoryUrl>https://github.com/TanerSaydam/TS.GenericRepository.NuGet</RepositoryUrl>
1414
<PackageId>TS.EntityFrameworkCore.GenericRepository</PackageId>
1515
<AssemblyVersion></AssemblyVersion>
1616
<FileVersion></FileVersion>
17-
<Version>8.0.3</Version>
17+
<Version>8.0.4</Version>
1818
<Authors>Taner Saydam</Authors>
1919
<PackageTags>genericrepository</PackageTags>
2020
<Product>Generic Repository</Product>
21+
<RepositoryType>git</RepositoryType>
2122
</PropertyGroup>
2223

2324
<ItemGroup>

GenericRepository/IRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public interface IRepository<TEntity>
2222
Task AddAsync(TEntity entity, CancellationToken cancellationToken = default);
2323
void Add(TEntity entity);
2424
Task AddRangeAsync(ICollection<TEntity> entities, CancellationToken cancellationToken = default);
25+
void AddRange(ICollection<TEntity> entities);
2526
void Update(TEntity entity);
2627
void UpdateRange(ICollection<TEntity> entities);
2728
Task DeleteByIdAsync(string id);

GenericRepository/Repository.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,8 @@ public void UpdateRange(ICollection<TEntity> entities)
145145
Entity.UpdateRange(entities);
146146
}
147147

148-
148+
public void AddRange(ICollection<TEntity> entities)
149+
{
150+
Entity.AddRange(entities);
151+
}
149152
}

README.md

Lines changed: 2 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task<IList<User>> GetAllAsync(CancellationToken cancellationToken)
5656
## Dependency Injection
5757
```CSharp
5858
builder.Service.AddScoped<IUserRepository, UserRepository>();
59-
builder.Service.AddScoped<IUnitOfWork>(cfr => cfr.GetRequiredService<ApplicationDbContext>());
59+
builder.Services.AddScoped<IUnitOfWork>(srv => srv.GetRequiredService<ApplicationDbContext>());
6060
```
6161

6262
## Methods
@@ -91,158 +91,4 @@ public interface IRepository<TEntity>
9191
void DeleteRange(ICollection<TEntity> entities);
9292

9393
}
94-
```
95-
96-
```Csharp
97-
public class Repository<TEntity, TContext> : IRepository<TEntity>
98-
where TEntity : class
99-
where TContext : DbContext
100-
{
101-
private readonly TContext _context;
102-
private DbSet<TEntity> Entity;
103-
104-
public Repository(TContext context)
105-
{
106-
_context = context;
107-
Entity = _context.Set<TEntity>();
108-
}
109-
110-
public void Add(TEntity entity)
111-
{
112-
Entity.Add(entity);
113-
}
114-
115-
public async Task AddAsync(TEntity entity, CancellationToken cancellationToken = default)
116-
{
117-
await Entity.AddAsync(entity, cancellationToken);
118-
}
119-
120-
public async Task AddRangeAsync(ICollection<TEntity> entities, CancellationToken cancellationToken = default)
121-
{
122-
await Entity.AddRangeAsync(entities, cancellationToken);
123-
}
124-
125-
public bool Any(Expression<Func<TEntity, bool>> expression)
126-
{
127-
return Entity.Any(expression);
128-
}
129-
130-
public async Task<bool> AnyAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default)
131-
{
132-
return await Entity.AnyAsync(expression, cancellationToken);
133-
}
134-
135-
public void Delete(TEntity entity)
136-
{
137-
Entity.Remove(entity);
138-
}
139-
140-
public async Task DeleteByExpressionAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default)
141-
{
142-
TEntity entity = await Entity.Where(expression).AsNoTracking().FirstOrDefaultAsync(cancellationToken);
143-
Entity.Remove(entity);
144-
}
145-
146-
public async Task DeleteByIdAsync(string id)
147-
{
148-
TEntity entity = await Entity.FindAsync(id);
149-
Entity.Remove(entity);
150-
}
151-
152-
public void DeleteRange(ICollection<TEntity> entities)
153-
{
154-
Entity.RemoveRange(entities);
155-
}
156-
157-
public IQueryable<TEntity> GetAll()
158-
{
159-
return Entity.AsNoTracking().AsQueryable();
160-
}
161-
162-
public IQueryable<TEntity> GetAllWithTracking()
163-
{
164-
return Entity.AsQueryable();
165-
}
166-
167-
public async Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default, bool isTrackingActive = true)
168-
{
169-
TEntity entity;
170-
if (isTrackingActive)
171-
{
172-
entity = await Entity.Where(expression).FirstOrDefaultAsync(cancellationToken);
173-
}
174-
else
175-
{
176-
entity = await Entity.Where(expression).AsNoTracking().FirstOrDefaultAsync(cancellationToken);
177-
}
178-
179-
return entity;
180-
}
181-
182-
public TEntity GetByExpression(Expression<Func<TEntity, bool>> expression)
183-
{
184-
TEntity entity = Entity.Where(expression).AsNoTracking().FirstOrDefault();
185-
return entity;
186-
}
187-
188-
public async Task<TEntity> GetByExpressionAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default)
189-
{
190-
TEntity entity = await Entity.Where(expression).AsNoTracking().FirstOrDefaultAsync(cancellationToken);
191-
return entity;
192-
}
193-
194-
public TEntity GetByExpressionWithTracking(Expression<Func<TEntity, bool>> expression)
195-
{
196-
TEntity entity = Entity.Where(expression).FirstOrDefault();
197-
return entity;
198-
}
199-
200-
public async Task<TEntity> GetByExpressionWithTrackingAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancellationToken = default)
201-
{
202-
TEntity entity = await Entity.Where(expression).FirstOrDefaultAsync(cancellationToken);
203-
return entity;
204-
}
205-
206-
public TEntity GetFirst()
207-
{
208-
TEntity entity = Entity.AsNoTracking().FirstOrDefault();
209-
return entity;
210-
}
211-
212-
public async Task<TEntity> GetFirstAsync(CancellationToken cancellationToken = default)
213-
{
214-
TEntity entity = await Entity.AsNoTracking().FirstOrDefaultAsync(cancellationToken);
215-
return entity;
216-
}
217-
218-
public IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression)
219-
{
220-
return Entity.AsNoTracking().Where(expression).AsQueryable();
221-
}
222-
223-
public IQueryable<TEntity> WhereWithTracking(Expression<Func<TEntity, bool>> expression)
224-
{
225-
return Entity.Where(expression).AsQueryable();
226-
}
227-
228-
public void Update(TEntity entity)
229-
{
230-
Entity.Update(entity);
231-
}
232-
233-
public void UpdateRange(ICollection<TEntity> entities)
234-
{
235-
Entity.UpdateRange(entities);
236-
}
237-
}
238-
239-
240-
```
241-
242-
```Csharp
243-
public interface IUnitOfWork
244-
{
245-
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
246-
int SaveChanges();
247-
}
248-
```
94+
```

0 commit comments

Comments
 (0)