-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDocumentBase.cs
45 lines (38 loc) · 1.5 KB
/
DocumentBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Newtonsoft.Json;
using System;
namespace DataModel
{
/// <summary>
/// The base class for classes that are stored JSON documents in a Cosmos DB collection.
/// </summary>
public abstract class DocumentBase
{
protected DocumentBase()
{
// Set the ID to a new guid. This way we have a unique ID
// in case it is not explicitly set.
this.Id = Guid.NewGuid().ToString();
// Set the document type to match the name of the class.
this.DocumentType = this.GetType().Name;
// Set the partition by default to match the document type
// to have some kind ofdistribution in case the partition
// is not set in a derived class.
this.Partition = this.DocumentType;
}
/// <summary>
/// The unique ID of the document.
/// </summary>
[JsonProperty("id")]
public string Id { get; set; }
/// <summary>
/// Use in Cosmos DB as partition key to distribute documents across multiple partitions.
/// </summary>
public virtual string Partition { get; protected set; }
/// <summary>
/// The class name of the document. Enables you to look for particular types of documents.
/// Defaults to the name of the class, but you can override the property to set the type
/// to something else.
/// </summary>
public virtual string DocumentType { get; protected set; }
}
}