【问题标题】:How to join two table values in Sqlite Xamarin form?如何以 Sqlite Xamarin 形式连接两个表值?
【发布时间】:2017-05-05 10:09:02
【问题描述】:

我从 C# 在我的 Xamarin 中创建了两个模型 Outlet_model 和 TbTrdDocModel。 我可以分别访问每个模型的值,但现在我想在 SQLite 中加入这两个表。 有人知道如何加入这两个模型来访问列表视图中的数据吗?提前致谢。

【问题讨论】:

    标签: c# sqlite xamarin


    【解决方案1】:

    试试这个

    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 不支持。你知道如何解决这个问题吗?
    • SQLite 似乎不支持通过 Linq 连接,请参阅 stackoverflow.com/questions/27260905/… 以获得更多帮助。
    猜你喜欢
    • 2019-07-18
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 2019-05-01
    • 1970-01-01
    相关资源
    最近更新 更多