Browse Source

Update MongoDB.md document translation

pull/536/head
edison 8 years ago
parent
commit
85824efc86
  1. 14
      docs/zh-Hans/MongoDB.md

14
docs/zh-Hans/MongoDB.md

@ -4,7 +4,7 @@
### 安装 ### 安装
集成MongoDB需要用到`Volo.Abp.MongoDB`这个包。将它安装到你的项目中(如果是多层架构,安装到数据层和基础设施层): 集成MongoDB需要用到`Volo.Abp.MongoDB`这个包.将它安装到你的项目中(如果是多层架构,安装到数据层和基础设施层):
``` ```
Install-Package Volo.Abp.MongoDB Install-Package Volo.Abp.MongoDB
@ -28,7 +28,7 @@ namespace MyCompany.MyProject
### 创建一个Mongo Db Context ### 创建一个Mongo Db Context
ABP中引入了 **Mongo Db Context** 的概念(跟Entity Framework Core的DbContext很像)让使用和配置集合变得更简单。举个例子: ABP中引入了 **Mongo Db Context** 的概念(跟Entity Framework Core的DbContext很像)让使用和配置集合变得更简单.举个例子:
```c# ```c#
public class MyDbContext : AbpMongoDbContext public class MyDbContext : AbpMongoDbContext
@ -48,8 +48,8 @@ public class MyDbContext : AbpMongoDbContext
``` ```
* 继承 `AbpMongoDbContext` 类 * 继承 `AbpMongoDbContext` 类
* 为每一个mongo集合添加一个公共的 `IMongoCollection<TEntity>` 属性。ABP默认使用这些属性创建默认的仓储 * 为每一个mongo集合添加一个公共的 `IMongoCollection<TEntity>` 属性.ABP默认使用这些属性创建默认的仓储
* 重写 `CreateModel` 方法,可以在方法中配置集合(如设置集合在数据库中的名字) * 重写 `CreateModel` 方法,可以在方法中配置集合(如设置集合在数据库中的名字)
### 将 Db Context 注入到依赖注入中 ### 将 Db Context 注入到依赖注入中
@ -77,7 +77,7 @@ namespace MyCompany.MyProject
#### 添加默认的仓储 #### 添加默认的仓储
在注入的时候使用 `AddDefaultRepositories()`, ABP就能自动为Db Context中的每一个实体创建 [仓储](Repositories.md): 在注入的时候使用 `AddDefaultRepositories()`, ABP就能自动为Db Context中的每一个实体创建 [仓储](Repositories.md):
````C# ````C#
services.AddMongoDbContext<MyDbContext>(options => services.AddMongoDbContext<MyDbContext>(options =>
@ -86,7 +86,7 @@ services.AddMongoDbContext<MyDbContext>(options =>
}); });
```` ````
这样就会默认为每一个聚合根实体(继承自AggregateRoot的类)创建一个仓储。如果你也想为其他的实体创建仓储,将 `includeAllEntities` 设置为 `true`就可以了: 这样就会默认为每一个聚合根实体(继承自AggregateRoot的类)创建一个仓储.如果你也想为其他的实体创建仓储,将 `includeAllEntities` 设置为 `true`就可以了:
```c# ```c#
services.AddMongoDbContext<MyDbContext>(options => services.AddMongoDbContext<MyDbContext>(options =>
@ -95,4 +95,4 @@ services.AddMongoDbContext<MyDbContext>(options =>
}); });
``` ```
现在可以在你的服务中注入并使用`IRepository<TEntity>` 或 `IQueryableRepository<TEntity>`了。 现在可以在你的服务中注入并使用`IRepository<TEntity>` 或 `IQueryableRepository<TEntity>`了.
Loading…
Cancel
Save