Search code examples
servicestackormlite-servicestack

Is it possible to create a cross-database query with ServiceStack ORMLite?


Pretty much summed up in the title.

Trying to hit a table in one database and join it to a table in another database on the same server.

I would have assumed an attribute for Database that I could decorate the POCO with, but do not see one that would be appropriate.

Currently using this syntax:

var result = db.Select<Model.Dto>(
                    db.From<Data.Dto1>()
                        .Join<Data.Dto2>(d1, d2) => d1.Id == d2.Id));

Solution

  • There's no specific attribute for specifying an external database but in RDBMS's that support cross-database queries you should be able to use the [Schema] attribute, e.g:

    [Schema("Server1.Database1.dbo")]
    public class Dto { ... }