Question

How to Select data using Service.OrmLite from two tables JOINwithout creating another Poco (Coal+Data) only for that purpose.

I have Poco for Coal and for CoalData like:

class Coal {
    // PK
    public long Id {get; set;}
    public string Name {get; set;}
}

class CoalData {
    // FK
    public long Id {get; set;}
    public int Prop1 {get; set;}
    ....
}

In Dapper it's simple like:

var personWithAddress = connection
    .Query<Person, Address, Extra, Tuple<Person, Address, Extra>>
    (sql, (p, a, e) => Tuple.Create(p, a, e), splitOn: "AddressId,Id").First();
Was it helpful?

Solution

ServiceStack.OrmLite does not support joining two or more tables like you suggest. It currently only supports simple expressions, and for Joins it recommends falling back to raw SQL queries. See here for OrmLite functionality.

For anything more complex (e.g. queries with table joins) you can still easily fall back to raw SQL queries as seen below.

However ServiceStack.OrmLite will likely get better support for joins in the near future, as this is the top open feature request, but under the commercial ServiceStack offering.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top