question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] three-levels tree

See original GitHub issue

Hello!! I’m working with data structured in three levels

// all public and {get; set;}
class A {
  int Id;
  List<B> Bs;
}
class B {
  int Id;
  List<C> Cs;
}
class C {
  int Id;
  bool Happy;
}

BsonMapper.Global.Entity<C>().Id(x => x.Id, false);
BsonMapper.Global.Entity<B>().Id(x => x.Id, false).DbRef(x => x.Cs, "cs");
BsonMapper.Global.Entity<A>().Id(x => x.Id, false).DbRef(x => x.Bs, "bs");
db = new LiteDatabase($"Filename={dbPath};Password={password}", BsonMapper.Global);

a = new A {Id = 1};
b1 = new B {Id = 1};
b2 = new B {Id = 2};
c1 = new C {Id = 1};
c2 = new C {Id = 2};
c3 = new C {Id = 3};

a.Bs.Add(b1);
a.Bs.Add(b2);
b1.Cs.Add(c1);
b1.Cs.Add(c2);
b2.Cs.Add(c3);

var dba = db.GetCollection<A>().Add(a);
var res = dba.Include(x => x.Bs).FindAll().ToList();

Question 1: res will include all A and their children B… but how to include C too (they are contained in B.Cs) ? Question 2: if I use a configuration like Nodes and Archs, stored in 2 different collections, is it possible to investigate the graph in depth for n levels?

Thank you very much in advice 😉 bye!!!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
lbnascimentocommented, May 29, 2020

@dxmann Yes, you must manually insert all referenced documents.

It is possible to navigate through the documents, but you’ll need to use Bson Expressions. Here’s an example:

var colAs = db.GetCollection<A>("as").Include("$.Bs").Include("$.Bs[*].Cs");
var colBs = db.GetCollection<B>("bs").Include("$.Cs");
var colCs = db.GetCollection<C>("cs");

var r = colAs.Find("count($.Bs) > 0 and $.Bs[*].Cs[*].Happy all = true").ToList();
// returns all As for which Bs is not empty and all Cs in all Bs have Happy = true
0reactions
dxmanncommented, May 29, 2020

Ok, Thank you very much!! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved Q1) Consider a binary tree that has three levels
Question : Q1) Consider a binary tree that has three levels (height=depth=2). a. What is the maximum number of nodes in this tree?...
Read more >
Top 50 Tree Coding Problems for Interviews
Problems in this Article are divided into three Levels so that readers can practice according to the difficulty level step by step.
Read more >
Solved 1. Consider a binary tree that has three levels. a.
Question : 1. Consider a binary tree that has three levels. a. What is the maximum number of nodes in this tree? b....
Read more >
Drill down and drill up in Tree map up to three levels
I am trying to apply drill down concept in Treemap up to 3 three levels. For an instance, I took superstore data and...
Read more >
Tree testing 101 - Tree testing overview
Tree testing is a fast and powerful means to test the navigation tree of your website or app, or even test new tree...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found