Question

I am using an ORM that uses POCOs.

Each table (class) contains references to other tables.

public class Table1 {
    [AutoIncrement]
    public Int32 Id { get; set; }
    [Index(Unique = true)]
    public string FieldA { get; set; }
}

public Table2 {
    [AutoIncrement]
    public Int32 Id { get; set; }
    [Index(Unique = true)]
    public Table1 FieldA { get; set; }
    public int FieldB { get; set; }
}

public Table3 {
    [AutoIncrement]
    public Int32 Id { get; set; }
    [Index(Unique = true)]
    public List<Table2> FieldA { get; set; }
    [References(typeof(Table2))]
    public int Table2_id { get; set; }
}

How would I populate a tree of Table3 which unrolls the referenced Table2 and subsequent Table1 into subtrees?

Thanks for all suggestions

Was it helpful?

Solution

May be something like this?

var root = new {TopLevelNodes = Table3.Select(t3=> new {Id = t3.Table2_id, SubLevel = t3.FieldA.Select(t2=>new {t2.FieldA})})};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top