I’ve just added support for specifying different Named Connections by Type in this commit.
This lets you use the new [NamedConnection]
attribute to have AutoQuery use a different named connection that’s registered in the AppHost as normal:
var dbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);
container.Register<IDbConnectionFactory>(dbFactory);
dbFactory.RegisterConnection("SqlServer",
"Server=localhost;Database=test;User Id=test;Password=test;",
SqlServer2012Dialect.Provider);
Then you can use the [NamedConnection]
on any Table you want to use the named connection instead, e.g:
[NamedConnection("SqlServer")]
public class Rockstar { ... }
[Route("/query/rockstars")]
public class QueryRockstars : QueryBase<Rockstar> { ... }
This is the preferred approach as it doesn’t need to rely on using the static RequestContext to hot-swap which Db connection gets used.
This change is available from v4.0.53 that’s now available on MyGet.