Skip to content

Commit 941c379

Browse files
committed
adding the range insert for mongo
1 parent 6112a48 commit 941c379

5 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/CodeChavez.Repository.Pattern.MongoDB/CodeChavez.Repository.Pattern.MongoDB.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<Title>CodeChavez Repository Pattern MongoDB Library</Title>
1010
<Authors>Victor A Chavez</Authors>
1111
<Product>CodeChavez.Repository.Pattern.MongoDB</Product>
12-
<Version>10.0.0-preview1</Version>
13-
<Copyright>2020-2025</Copyright>
12+
<Version>10.0.0-preview2</Version>
13+
<Copyright>2020-2026</Copyright>
1414
<Description>Has some useful extension and utilities that allow for every day development</Description>
1515
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1616
<PackageReadmeFile>README.md</PackageReadmeFile>

src/CodeChavez.Repository.Pattern.MongoDB/MongoRepository.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,28 @@ public async Task<TEntity> AddAsync(TEntity entity, CancellationToken cancellati
2828
{
2929
_ = await _dbContext.Set<TEntity>().AddAsync(entity, cancellationToken);
3030
_dbContext.Database.AutoTransactionBehavior = AutoTransactionBehavior.Never;
31-
await _dbContext.SaveChangesAsync();
31+
await _dbContext.SaveChangesAsync(cancellationToken);
3232

3333
if (_mediator.IsNotNull())
3434
await _mediator.DispatchDomainDocumentEventsAsync(entity);
3535

3636
return entity;
3737
}
3838

39+
public async Task AddRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)
40+
{
41+
if (entities == null)
42+
throw new ArgumentNullException(nameof(entities));
43+
44+
if (!entities.Any())
45+
throw new ArgumentException("The collection of entities cannot be empty.", nameof(entities));
46+
47+
_dbContext.Set<TEntity>().AddRange(entities);
48+
49+
_dbContext.Database.AutoTransactionBehavior = AutoTransactionBehavior.WhenNeeded;
50+
await _dbContext.SaveChangesAsync(cancellationToken);
51+
}
52+
3953
public Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default)
4054
{
4155
throw new NotImplementedException();

src/CodeChavez.Repository.Pattern.Postgres/CodeChavez.Repository.Pattern.Postgres.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<Title>CodeChavez Repository Pattern Postgres Library</Title>
1010
<Authors>Victor A Chavez</Authors>
1111
<Product>CodeChavez.Repository.Pattern.Postgres</Product>
12-
<Version>10.0.0-preview1</Version>
13-
<Copyright>2020-2025</Copyright>
12+
<Version>10.0.0-preview2</Version>
13+
<Copyright>2020-2026</Copyright>
1414
<Description>Has some useful extension and utilities that allow for every day development</Description>
1515
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1616
<PackageReadmeFile>README.md</PackageReadmeFile>

src/CodeChavez.Repository.Pattern/CodeChavez.Repository.Pattern.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<Title>CodeChavez Repository Pattern Library</Title>
1010
<Authors>Victor A Chavez</Authors>
1111
<Product>CodeChavez.Repository.Pattern</Product>
12-
<Version>10.0.0</Version>
13-
<Copyright>2020-2025</Copyright>
12+
<Version>10.0.1</Version>
13+
<Copyright>2020-2026</Copyright>
1414
<Description>Has some useful extension and utilities that allow for every day development</Description>
1515
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1616
<PackageReadmeFile>README.md</PackageReadmeFile>

src/CodeChavez.Repository.Pattern/Interfaces/IRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Task<IEnumerable<TEntity>> FindAsync(
2222

2323
public interface INoSQLRepository<TEntity> where TEntity : DomainDocument
2424
{
25+
Task AddRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)
2526
Task<TEntity> AddAsync(TEntity entity, CancellationToken cancellationToken = default);
2627
Task<TEntity> UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
2728
Task DeleteAsync<TKey>(TKey id, CancellationToken cancellationToken = default);

0 commit comments

Comments
 (0)