Litedb: [QUESTION] Include Functionality For Nested Object , like v4 Includeall ?

Created on 25 Apr 2020  路  4Comments  路  Source: mbdavid/LiteDB

I am stuck on finding solution for below query. using litedb v5

Query :db.GetCollection<PurchaseOrder().Include(x=>x.OrderItems) , want to include Model
DTOs :

public class PurchaseOrder
    {
        public int Id { get; set; }
        public DateTime DatePurchased { get; set; }
        public List<OrderDetail> OrderItems { get; set; }
        public string Note { get; set; }
    }

  public class OrderDetail
    {    
        public Model Model { get; set; }
        public decimal Price { get; set; }
        public int Qty { get; set; }
    }
 public class Model 
    { 
        public int Id { get; set; }
        public string Name { get; set; }
  }

Issue : when i run above query it gives me result but Model is is always null.
Any help will be appreciated !!

question

Most helpful comment

db.GetCollection<PurchaseOrder>().Include("$.OrderItems[*].Model")
Thanks !! It works.
Is there any way to define IncludeAll ? without explicitly specifying each dbRef ?

All 4 comments

assuming OrderItems and Model are BsonRefed, have you tried db.GetCollection<PurchaseOrder>().Include(x=>x.OrderItems).Include(x => x.OrderItems.Model)?

i am not getting Include(x => x.OrderItems.Model)
As OrderItems is list..its showing me all functions related to List e.g. Add ,FirstOrDefault

I tried Include(x => x.OrderItems.FirstOrDefault().Model) but it only fetches the value for first item and not all.

totally missed the fact that OrderItems was a list and that, probably OrderItems isn麓t BsonRefed 馃檮

assuming only Model is declared as BsonRef, how about
db.GetCollection<PurchaseOrder>().Include("$.OrderItems[*].Model");?

db.GetCollection<PurchaseOrder>().Include("$.OrderItems[*].Model")
Thanks !! It works.
Is there any way to define IncludeAll ? without explicitly specifying each dbRef ?

Was this page helpful?
0 / 5 - 0 ratings