Saving data to multiple collections in DocumentDb

In DocumentDb, what is the best way and place for decoupling data to be stored in separate collections?

So far, most examples of how to manage data with DocumentDb use simple objects, but in real life we ​​almost never do. I just want to understand how and where I need to handle complex classes before I save them as Json objects in DocumentDb.

Let's look at the following example. I will save project information in the project collection, but I DO NOT want to keep the full names of people in the project team as part of the project document. I just want to keep their EmployeeId in the project document. I have a separate collection of employees where I want to save information about a person / employee. My project object is as follows:

public class Project
{
   [JsonProperty(PropertyName="id")]
   public int ProjectId {get; set;}

   [JsonProperty(PropertyName="projectName")]
   public string ProjectName {get; set;}

   [JsonProperty(PropertyName="projectType")]
   public string ProjectType {get; set;}

   [JsonProperty(PropertyName="projectTeam")]
   public List<TeamMember> ProjectTeam {get; set}
}

My TeamMember class inherits an Employee object and looks like this:

public class TeamMember : Employee
{
   [JsonProperty(PropertyName="position")]
   public string Position {get; set;}
}

My Employee class is as follows:

public class Employee
{
   [JsonProperty(PropertyName="id")]
   public int EmployeeId {get; set;}

   [JsonProperty(PropertyName="firstName")]
   public string FirstName {get; set;}

   [JsonProperty(PropertyName="lastName")]
   public string LastName {get; set;}

   [JsonProperty(PropertyName="gender")]
   public string Gender {get; set;}

   [JsonProperty(PropertyName="emailAddress")]
   public string EmailAddress {get; set;}
}

Before saving to the project collection, here is an example of my project document:

{
   id: 12345,
   projectName: "My first project",
   projectType: "Construction Project",
   projectTeam: [
      { id: 7777, position: "Engineer" },
      { id: 8998, position: "Project Manager" }
   ]
}

As you can see, I separated the project information from the employee data in order to save it in my own collections, projects and employee collections, respectively.

, . , , . , , , DocumentDb.

, , , , :

  • Project JSON # JSON DocumentDb .
  • Project DocumentDb JavaScript, DocumentDb.

:

  • ?
  • ?
  • ? , POCO DocumentDb, . DocumentDb ? , ?

. .

+4
1

NoSql, , .

, . , , ..

, , , , , .

; , ... . TeamMember: Employee ( Employee) TeamMember, , JSON... ..

class TeamMember
{
   int id {get;set;}
   string position {get;set;}
}

, DocumentDB , JSON, , . Employee - .

, , , , JSON Project, JSON, . Project JsonConverter, DocumentDB , .

+7

All Articles