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

前端 未结 2 554
失恋的感觉
失恋的感觉 2021-01-19 00:43

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:

相关标签:
2条回答
  • 2021-01-19 01:28

    I was able to use it properly, you can try.

     var db = new SQLiteAsyncConnection(_dbPath);
     var query = from person in await db.Table<Person>().ToListAsync()
                        join job in await db.Table<Job>().ToListAsync()
                        on person.JobID = job.ID
                        select new
                        {
                            Name=person.Name
                        };
    
    0 讨论(0)
  • 2021-01-19 01:36

    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");
    
    0 讨论(0)
提交回复
热议问题