Update README.md
This commit is contained in:
committed by
GitHub
parent
90ba1e4fc6
commit
b843f2de7f
@@ -12,7 +12,7 @@ You are responsible for managing its lifetime, it is advised to setup this repos
|
|||||||
|
|
||||||
Here is an example of repository usage, where the TestRepository is implementing 2 custom methods:
|
Here is an example of repository usage, where the TestRepository is implementing 2 custom methods:
|
||||||
|
|
||||||
```
|
```csharp
|
||||||
public interface ITestRepository : IBaseMongoRepository
|
public interface ITestRepository : IBaseMongoRepository
|
||||||
{
|
{
|
||||||
void DropTestCollection<TDocument>();
|
void DropTestCollection<TDocument>();
|
||||||
@@ -40,14 +40,14 @@ Here is an example of repository usage, where the TestRepository is implementing
|
|||||||
|
|
||||||
The repository can be instantiated like so:
|
The repository can be instantiated like so:
|
||||||
|
|
||||||
```
|
```csharp
|
||||||
ITestRepository testRepository = new TestRepository(connectionString, "MongoDbTests");
|
ITestRepository testRepository = new TestRepository(connectionString, "MongoDbTests");
|
||||||
```
|
```
|
||||||
|
|
||||||
## Adding documents
|
## Adding documents
|
||||||
To add a document, its class must inherit from the `Document` class or implement the `IDocument` interface:
|
To add a document, its class must inherit from the `Document` class or implement the `IDocument` interface:
|
||||||
|
|
||||||
```
|
```csharp
|
||||||
public class MyDocument : Document
|
public class MyDocument : Document
|
||||||
{
|
{
|
||||||
public MyDocument()
|
public MyDocument()
|
||||||
@@ -60,7 +60,7 @@ To add a document, its class must inherit from the `Document` class or implement
|
|||||||
|
|
||||||
The `IDocument` interface can be seen below:
|
The `IDocument` interface can be seen below:
|
||||||
|
|
||||||
```
|
```csharp
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class represents a basic document that can be stored in MongoDb.
|
/// This class represents a basic document that can be stored in MongoDb.
|
||||||
/// Your document must implement this class in order for the MongoDbRepository to handle them.
|
/// Your document must implement this class in order for the MongoDbRepository to handle them.
|
||||||
@@ -76,7 +76,7 @@ The `IDocument` interface can be seen below:
|
|||||||
This repository also allows you to partition your document across multiple collections, this can be useful if you are running a SaaS application and want to keep good performance.
|
This repository also allows you to partition your document across multiple collections, this can be useful if you are running a SaaS application and want to keep good performance.
|
||||||
|
|
||||||
To use partitioned collections, you must define your documents using the PartitionedDocument class, which implements the IPartitionedDocument interface:
|
To use partitioned collections, you must define your documents using the PartitionedDocument class, which implements the IPartitionedDocument interface:
|
||||||
```
|
```csharp
|
||||||
public class MyPartitionedDocument : PartitionedDocument
|
public class MyPartitionedDocument : PartitionedDocument
|
||||||
{
|
{
|
||||||
public MyPartitionedDocument(string myPartitionKey) : base(myPartitionKey)
|
public MyPartitionedDocument(string myPartitionKey) : base(myPartitionKey)
|
||||||
@@ -90,7 +90,7 @@ To use partitioned collections, you must define your documents using the Partiti
|
|||||||
This partitioned key will be used as a prefix to your collection name.
|
This partitioned key will be used as a prefix to your collection name.
|
||||||
The collection name is derived from the name of the type of your document, is set to camel case, and is pluralized using a class taken from Humanizer (https://github.com/Humanizr/Humanizer).
|
The collection name is derived from the name of the type of your document, is set to camel case, and is pluralized using a class taken from Humanizer (https://github.com/Humanizr/Humanizer).
|
||||||
|
|
||||||
```
|
```csharp
|
||||||
var myDoc = new MyPartitionedDocument("myPartitionKey");
|
var myDoc = new MyPartitionedDocument("myPartitionKey");
|
||||||
_testRepository.AddOne(myDoc);
|
_testRepository.AddOne(myDoc);
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user