如何在Sqlite Xamarin表单中连接两个表值?
问题描述:
我在C#中创建了Xamarin中的两个Outlet_model和TbTrdDocModel模型。 我可以分别访问每个模型的值,但现在我想在SQLite中加入两个表。 有人知道如何加入这两个模型来访问列表视图中的数据吗?提前致谢。如何在Sqlite Xamarin表单中连接两个表值?
答
试试这个
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; }
}
查询:
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();
亲爱的周杰伦帕特尔。非常感谢您的源代码。我已经使用SQLite尝试了xamarin格式的代码,但它显示Join并不支持。你有任何想法如何解决这个问题吗? – Sheraz
似乎SQLite不支持通过Linq加入 请参阅http://*.com/questions/27260905/join-tables-in-sqlite-net-with-linq-on-xamarin-android-is-not-supported for更多的帮助。 –