I have created two models Outlet_model and TbTrdDocModel in my Xamarin from C#. I can access the values from each model separately but now I want to join both tables in SQLite. Do anybody know how to join these two model to access the data in the listview? Thanks in Advance.
Asked
Active
Viewed 1,515 times
1 Answers
1
try this
public class MusicItems
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public String Name { get; set; }
public String Tension { get; set; }
public String Category { get; set; }
public String Subcategory { get; set; }
public int ResId { get; set; }
public int LoopStart { get; set; }
}
public class Playlist
{
public String Name { get; set; }
public int ResId { get; set; }
public int LoopStart { get; set; }
}
public class Themes
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public String ThemeName { get; set; }
public String ThemeDesc { get; set; }
public int ThemeImg { get; set; }
public String ThemeCategory { get; set; }
public String ThemeSubcategory { get; set; }
}
public class MusicInThemes
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public int ResId { get; set; }
public int ThemeId { get; set; }
}
The query:
return database.Table<MusicItems>()
.Join(database.Table<MusicInThemes>().Where(t => t.ThemeId == ThemeID)
,m =>m.ResId
,t => t.ResId
,(m,t) => new {mym = m, myt = t })
.Select(a => new Playlist
{
Name = a.mym.Name,
ResId = a.mym.ResId,
LoopStart = 0
})
.ToList();

Jay Patel
- 528
- 8
- 26
-
Dear Jay Patel. Thank you very much for your source code. I have tried your code in xamarin form using SQLite.but it is showing that Join is not supporting.Do you have any idea how to solve this issue? – Sheraz May 08 '17 at 03:56
-
Seems like SQLite does not support join via Linq Refer http://stackoverflow.com/questions/27260905/join-tables-in-sqlite-net-with-linq-on-xamarin-android-is-not-supported for more help. – Jay Patel May 08 '17 at 07:42