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.
You could get the Customers like this:
using System.Linq;
collectionCarts.SelectMany(c => c.OrderList.Select(o => o.Customer));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With