【发布时间】:2017-05-05 10:09:02
【问题描述】:
我从 C# 在我的 Xamarin 中创建了两个模型 Outlet_model 和 TbTrdDocModel。 我可以分别访问每个模型的值,但现在我想在 SQLite 中加入这两个表。 有人知道如何加入这两个模型来访问列表视图中的数据吗?提前致谢。
【问题讨论】:
我从 C# 在我的 Xamarin 中创建了两个模型 Outlet_model 和 TbTrdDocModel。 我可以分别访问每个模型的值,但现在我想在 SQLite 中加入这两个表。 有人知道如何加入这两个模型来访问列表视图中的数据吗?提前致谢。
【问题讨论】:
试试这个
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();
【讨论】: