Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite Join in Windows 8 Metro C# with sqlite-net

I am using C# and SQLite for a Database for a Windows-8-Metro-App. I want to use a Join-Command, but don't know how to read the given back data. This will not work:

db.Query<Person>("SELECT * FROM Person, Job WHERE Person.JobID = Job.ID");

And this is not implemented:

db.Query<Person, Job>("SELECT * FROM Person, Job WHERE Person.JobID = Job.ID");

Someone has an idea how to do this?

like image 845
Berschi Avatar asked Sep 02 '12 09:09

Berschi


1 Answers

The join is fine, if antiquated - you should use the newer syntax

 SELECT * FROM Person INNER JOIN Job ON Person.JobID = Job.ID

Your problem is in what you are returning - you are returning both Person data and Job data - so you need to create a class that matches the data structure that you are returning - or return just a person, or a job.

 db.Query<Person>("SELECT Person.* FROM Person INNER JOIN Job ON Person.JobID = Job.ID");           
 db.Query<Job>("SELECT Job.* FROM Person INNER JOIN Job ON Person.JobID = Job.ID");
like image 120
podiluska Avatar answered Sep 18 '22 15:09

podiluska