Browse Source

Merge pull request #7383 from abpframework/auto-merge/rel-4-2/111

Merge branch dev with rel-4.2
pull/7414/head
maliming 6 years ago
committed by GitHub
parent
commit
72a8a15cd3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      docs/en/Entity-Framework-Core.md
  2. 56
      docs/en/MongoDB.md

3
docs/en/Entity-Framework-Core.md

@ -236,7 +236,8 @@ public class BookRepository
public async Task DeleteBooksByType(BookType type) public async Task DeleteBooksByType(BookType type)
{ {
await DbContext.Database.ExecuteSqlRawAsync( var dbContext = await GetDbContextAsync();
await dbContext.Database.ExecuteSqlRawAsync(
$"DELETE FROM Books WHERE Type = {(int)type}" $"DELETE FROM Books WHERE Type = {(int)type}"
); );
} }

56
docs/en/MongoDB.md

@ -149,7 +149,7 @@ public class Book : AggregateRoot<Guid>
} }
``` ```
(`BookType` is a simple enum here) And you want to create a new `Book` entity in a [domain service](Domain-Services.md): (`BookType` is a simple `enum` here) And you want to create a new `Book` entity in a [domain service](Domain-Services.md):
```csharp ```csharp
public class BookManager : DomainService public class BookManager : DomainService
@ -215,7 +215,8 @@ public class BookRepository :
BookType type, BookType type,
CancellationToken cancellationToken = default(CancellationToken)) CancellationToken cancellationToken = default(CancellationToken))
{ {
await Collection.DeleteManyAsync( var collection = await GetCollectionAsync(cancellationToken);
await collection.DeleteManyAsync(
Builders<Book>.Filter.Eq(b => b.Type, type), Builders<Book>.Filter.Eq(b => b.Type, type),
cancellationToken cancellationToken
); );
@ -253,7 +254,7 @@ public async override Task DeleteAsync(
### Access to the MongoDB API ### Access to the MongoDB API
In most cases, you want to hide MongoDB APIs behind a repository (this is the main purpose of the repository). However, if you want to access the MongoDB API over the repository, you can use `GetDatabase()` or `GetCollection()` extension methods. Example: In most cases, you want to hide MongoDB APIs behind a repository (this is the main purpose of the repository). However, if you want to access the MongoDB API over the repository, you can use `GetDatabaseAsync()` or `GetCollectionAsync()` extension methods. Example:
```csharp ```csharp
public class BookService public class BookService
@ -265,10 +266,10 @@ public class BookService
_bookRepository = bookRepository; _bookRepository = bookRepository;
} }
public void Foo() public async Task FooAsync()
{ {
IMongoDatabase database = _bookRepository.GetDatabase(); IMongoDatabase database = await _bookRepository.GetDatabaseAsync();
IMongoCollection<Book> books = _bookRepository.GetCollection(); IMongoCollection<Book> books = await _bookRepository.GetCollectionAsync();
} }
} }
``` ```
@ -390,36 +391,45 @@ If you have better logic or using an external library for bulk operations, you c
- You may use example template below: - You may use example template below:
```csharp ```csharp
public class MyCustomMongoDbBulkOperationProvider : IMongoDbBulkOperationProvider, ITransientDependency public class MyCustomMongoDbBulkOperationProvider
: IMongoDbBulkOperationProvider, ITransientDependency
{ {
public async Task DeleteManyAsync<TEntity>(IMongoDbRepository<TEntity> repository, public async Task DeleteManyAsync<TEntity>(
IEnumerable<TEntity> entities, IMongoDbRepository<TEntity> repository,
IClientSessionHandle sessionHandle, IEnumerable<TEntity> entities,
bool autoSave, IClientSessionHandle sessionHandle,
CancellationToken cancellationToken) bool autoSave,
CancellationToken cancellationToken)
where TEntity : class, IEntity where TEntity : class, IEntity
{ {
// Your logic here. // Your logic here.
} }
public async Task InsertManyAsync<TEntity>(IMongoDbRepository<TEntity> repository, public async Task InsertManyAsync<TEntity>(
IEnumerable<TEntity> entities, IMongoDbRepository<TEntity> repository,
IClientSessionHandle sessionHandle, IEnumerable<TEntity> entities,
bool autoSave, IClientSessionHandle sessionHandle,
CancellationToken cancellationToken) bool autoSave,
CancellationToken cancellationToken)
where TEntity : class, IEntity where TEntity : class, IEntity
{ {
// Your logic here. // Your logic here.
} }
public async Task UpdateManyAsync<TEntity>(IMongoDbRepository<TEntity> repository, public async Task UpdateManyAsync<TEntity>(
IEnumerable<TEntity> entities, IMongoDbRepository<TEntity> repository,
IClientSessionHandle sessionHandle, IEnumerable<TEntity> entities,
bool autoSave, IClientSessionHandle sessionHandle,
CancellationToken cancellationToken) bool autoSave,
CancellationToken cancellationToken)
where TEntity : class, IEntity where TEntity : class, IEntity
{ {
// Your logic here. // Your logic here.
} }
} }
``` ```
## See Also
* [Entities](Entities.md)
* [Repositories](Repositories.md)
Loading…
Cancel
Save