I am currently writing a Windows Store Application for Windows 8 and I am using SQLite for the persistence on the embedded database in a class library for windows apps. I am trying to join data from two different tables in my embedded database but SQLite keeps throwing a not supported exception from their GenerateCommand method.
I do currently have data in both tables and they both have a questionId in each table to join on. I've tried two different methods which both throw the same error.
The first method:
var q = (from gameTable in db.Table<Model.GameSaved>()
join qTable in db.Table<Questions>() on gameTable.QuestionId equals qTable.QuestionId
select qTable
).First();
The second method:
var q =
(from question in db.Table<Model.GameSaved>()
select question
).Join(db.Table<Questions>(),
game => game.QuestionId,
questionObject => questionObject.QuestionId,
(game,questionObject) => questionObject)
.First();
I'm not exactly sure what I'm missing here but it has to be something simple and obvious.
Syntax. The syntax for the SQLite CROSS JOIN is: SELECT columns FROM table1 CROSS JOIN table2; NOTE: Unlike an INNER or OUTER join, a CROSS JOIN has no condition to join the 2 tables.
In SQLite, the NATURAL JOIN is such a join that performs the same task as an INNER or LEFT JOIN, in which the ON or USING clause refers to all columns that the tables to be joined have in common. A natural join joins two tables by their common column names.
SQLite supports different types of SQL Joins, like INNER JOIN, LEFT OUTER JOIN, and CROSS JOIN. Each type of JOIN is used for a different situation as we will see in this tutorial.
Unfortunately, SQLite does not support the RIGHT JOIN clause and also the FULL OUTER JOIN clause. However, you can easily emulate the FULL OUTER JOIN by using the LEFT JOIN clause.
You are not missing anything. Joins via linq are not supported by Sqlite-net at this time. You can work around this by providing your own SQL and using the Query
method. Your first query from above would look something like:
var q = db.Query<Questions>(
"select Q.* from Questions Q inner join GameSaved G"
+ " on Q.QuestionId = G.QuestionId"
).First();
If you are so inclined, the Query
method also supports parameters. From the Sqlite-net readme:
db.Query<Val>(
"select 'Price' as 'Money', 'Time' as 'Date' from Valuation where StockId = ?",
stock.Id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With