Update: I’ve changed my design so Item has an OrderId and I’m explicitly searching for an Order by ID. It’s only a small amount of extra overhead and not required for all operations. A big part of my problem was losing details when an Order is sent across the wire between server and client, which isn’t even a Mongo issue - it’s a de/serialization issue.
The only change in the code sample above is changing Item.Order to Item.OrderId and removing [BsonIgnore]:
Order RetrieveOrder(string orderId)
{
var order = Orders.Find(Builders<Order>.Filter.Eq(order => order Id, orderId).SingleOrDefault();
foreach (item in order.Items)
item.OrderId = order.Id;
return order;
}
class Item
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string OrderId { get; set; }
}