Null ID and Insert as a child of a document using WebAPI

Viewed 33

I'm using MongoDB and I've designed my model as follows, now I have two problems:

  1. When I insert the child manually in the document, the ID of the child set to null

  2. How can I insert document as a child of a document using WebAPI?

public class Building
{
  [BsonId]
  [BsonRepresentation(BsonType.ObjectId)]
  public string Id { get; set; }
  public string Name { get; set; }
  public bool IsUpdating { get; set; }
  public ICollection<Telephones> Telephones { get; set; }
  public ICollection<Building> Childs { get; set; }
}

In my controller class, I've following method: [HttpPost]

public IActionResult Create(Building Building)
{
    _BuildingDb.Create(Building);
    return CreatedAtRoute("GetBuilding", new { id = Building.Id.ToString() }, Building);
}
0 Answers
Related