Get all elements from Lists inside a List

Viewed 9212

I have following data model:

    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; }
    }

Now I want to access the customers via queries on my cart collection. I tried something like this:

var collectionCarts = db.GetCollection<Cart>("carts");
var result = collectionCarts.Include("OrderList.Customer").Find(x => x.OrderList[0].Customer.CustomerId == 2);

However, all attempts result in an empty customer object. My database, which I checked with the LiteDB-Viewer seems to be OK.

2 Answers
Related