I'm using MongoDB and I've designed my model as follows, now I have two problems:
When I insert the child manually in the document, the ID of the child set to
nullHow 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);
}