c# - How can I JOIN or Attach multiple SQLite DBs using ServiceStack OrmLite? -
Excellent has a ton of features.
I have a scenario where I have two or more separate SQLite DBs, how can I join / attach them using OrmLite?
Do I have to write a RAW SQL or have some built-in features that I can use?
Thanks
Ormailite support that allows you to register multiple RDBMS connections under different names For example, for example:
// set default connection var dbFactory = new OrmLiteConnectionFactory "~ / App_Data / db.sqlite" .MapAbsolutePath (), SqliteDialect.Provider); // Set up multiple named connection dbFactory.RegisterConnection ("db1", "~ / App_Data / db1.sqlite" .mapAbsolutePath (), SqliteDialect.Provider); DbFactory.RegisterConnection ("db2", "~ / App_Data / db2.sqlite" .mapAbsolutePath (), SqliteDialect.Provider);
You can then access each SQLite DB with the registered name.
Because sklit does not support cross-database connectivity, you can not create an SQL query spread across multiple compartments, so if you want to merge the results from both of them, then you do it in code Such as:
var results = new list & lt; Table & gt; (); (Var db1 = dbFactory.OpenDbConnection ("db1")) (var db2 = dbFactory.OpenDbConnection ("db2")) {results.AddRange (db1.Select & lt; Table & gt; (q = & gt; ; Q.Category = category)); result. Adrange (Select DB 2. & lt; Table & gt; (q = & gt; q.Category = Category)); }
Comments
Post a Comment