1

How can we insert or retrieve master's details from the below represented Detail property using LiteDB (LiteDatabase) C#.net library?

class myEntityMaster{
        public int ID {get;set;}
        public string Name {get;set;}
        public List<myEntityDetail> Detail {get;set;} // this is the variable I want to valorize

}
class myEntityDetail{
    public int ID {get;set;}
    public int MasterID {get;set;}
    public string Description {get;set;}
}

Please note that I tried performing LiteDatabase.Insert() of myEntityMaster having Detail property filled with items, however when I call any LiteDatabase.Find function, the Detail property will be empty.

garry man
  • 445
  • 4
  • 14

1 Answers1

0

You can use BsonRef for doing this.

Or BsonMapper

public class Product
{
    public int ProductId { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
}

public class Order
{
    public int OrderId { get; set; }
    public DateTime OrderDate { get; set; }
    public List<Product> Products { get; set; }
}

BsonMapper.Global.Entity<Order>()
    .DbRef(x => x.Products, "products");

Usage

db.Query<Order>()
    .Include(x => x.Customer)
    .Include(x => x.Products)
    .ToList();
Fatih
  • 945
  • 15
  • 26