0

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

A T
  • 13,008
  • 21
  • 97
  • 158
  • Just realised that C# doesn't have the data-structures I take for granted built in. Fortunately [C5](https://github.com/sestoft/C5/) adds this much required feature-set. – A T May 16 '12 at 03:54

1 Answers1

0

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})})};
Val Bakhtin
  • 1,434
  • 9
  • 11
  • Hmm, that might be it, thanks. Though can you talk me through what it is? - E.g.: is it nested Lists or an actual Tree? – A T May 16 '12 at 03:57
  • Yes, linq plus anonymous classes, I do not see full picture what you are going to accomplish, but you may not need it at all, your class already related the way you want. – Val Bakhtin May 16 '12 at 04:25