A T
A T

Reputation: 13826

OrmLite with nested select queries

I have generalised my problem in order to cater to the largest number of people with similar issues.

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

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

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

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

How can I populate a List containing the complete information of Table4? I.e.: including the value of each field of its referenced tables—and the referenced tables of those

I would also be interested in how I could create a single CRUD form—from the JSON serialisation—which can create an entirely new Table4 entry nesting the CRUD forms for Table3, Table2 and Table1.

Thanks for all help

Upvotes: 2

Views: 4165

Answers (1)

mythz
mythz

Reputation: 143319

To read from multiple tables in 1 query you need to use an SQL JOIN that's mapped to a Merged Poco which matches the returned result-set, see the Shipper Examples in this answer for an example:

https://stackoverflow.com/a/8617860/85785

Upvotes: 1

Related Questions