我有以下数据模型:
public class Customer
{
[BsonId]
public int CustomerId { get; set; }
public string Name { get; set; }
}
public class Order
{
[BsonId]
public int OrderId { get; set; }
[BsonRef("customers")]
public Customer Customer { get; set; }
}
public class Cart
{
[BsonId]
public int CartID { get; set; }
public List<Order> OrderList { get; set; }
}
现在我想通过对我的购物车集合的查询来访问客户。我试过这样的事情:
var collectionCarts = db.GetCollection<Cart>("carts");
var result = collectionCarts.Include("OrderList.Customer").Find(x => x.OrderList[0].Customer.CustomerId == 2);
但是,所有尝试都会导致一个空的客户对象。我用 LiteDB-Viewer 检查的数据库似乎没问题。