sqlite无法识别通用列表

时间:2014-02-17 16:02:14

标签: c# sqlite windows-runtime windows-store

在Windows商店应用程序项目中,我从Web服务获得一个JSON,如下所示:http://paste2.org/jfMJ2AGA

我有这2个班级

public class media
{
    public string id { get; set; }
    public string type { get; set; }
    public string image { get; set; }
    public string video { get; set; }
    public string snapshot { get; set; }
    public string url { get; set; }
    public string snapshot_url { get; set; }
}

public class artigos
{
    public string menu { get; set; }
    public string submenu { get; set; }
    public string title { get; set; }
    public string subtitle { get; set; }
    public string description { get; set; }
    public List<media> media { get; set; }
}

并使用以下命令创建一个sqlite数据库:

dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Database.sqlite");

//start dB
using (var db = new SQLite.SQLiteConnection(dbPath))
{
    db.CreateTable<artigos>();
}

但是我收到了这个错误:

  

不了解System.Collections.Generic.List`1 [xxxxx.media]

我做错了吗?

2 个答案:

答案 0 :(得分:2)

Sqllite不支持列表。这意味着你无法拥有

public List<media> media { get; set; } 

答案 1 :(得分:0)

我对int []有同样的问题,我这样做了:

[Table(nameof(Folder))]
public class Folder
{
    public Folder()
    {
        // for SQLite
    }
    internal Folder(Json.Folder folder)
    {
        Id = folder.id;
        Title = folder.title;
        Lists = string.Join(",", folder.list_ids);
    }

    [PrimaryKey]
    public int Id { get; set; }
    public string Title { get; set; }
    public string Lists { get; set; }
    public int[] ListsArray => Lists.Split(',').Select(x => int.Parse(x)).ToArray();
}