【问题标题】:Using SQLite-Net Extensions and OneToMany relation使用 SQLite-Net 扩展和 OneToMany 关系
【发布时间】:2015-01-06 17:26:37
【问题描述】:

我在尝试为具有 OneToMany 关系的 Windows Phone 8.1 实现 SQLite-Extensions 示例时遇到了困难。我真的很想使用这个功能,但我正在努力让它发挥作用。就像在这个question 中一样,当我尝试将provided example 用于具有估值列表的Stocks 表时:

public class Stock
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [MaxLength(8)]
    public string Symbol { get; set; }

    [OneToMany(CascadeOperations = CascadeOperation.All)]      // One to many relationship with Valuation
    public List<Valuation> Valuations { get; set; }
}

public class Valuation
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    [ForeignKey(typeof(Stock))]     // Specify the foreign key
    public int StockId { get; set; }
    public DateTime Time { get; set; }
    public decimal Price { get; set; }

    [ManyToOne]      // Many to one relationship with Stock
    public Stock Stock { get; set; }
}

我尝试创建表时出现错误:

app_name.exe 中出现“System.NotSupportedException”类型的异常,但未在用户代码中处理其他信息:不了解 >System.Collections.Generic.List`1 [app_name.Model.modelName]

我最初包含了对 sqlite-net 和 SQLiteNetExtensions-PCL 的 NuGet 包引用,但之前提到这是由于引用了错误版本的 sqlite-net。

但是,我尝试下载 sqlite-net 的源代码并在本地构建它,但 SQLiteNetExtensions 并没有直接引用它。

我已经在我的解决方案中本地包含了源代码,它似乎并没有什么不同。有人有什么进一步的建议吗?我没有遇到任何可下载的示例。

【问题讨论】:

    标签: c# sqlite windows-phone-8.1 sqlite-net sqlite-net-extensions


    【解决方案1】:

    如果您添加了对 SQLiteNetExtensions-PCL 的引用,则您也不需要从 VS/Add References 手动添加对 SQLite 的引用,因为 Nuget 包包含适合您的正确版本。

    【讨论】:

    • 我确实设法让扩展正常工作。解决方案是您不需要从 VS/Add References 手动添加对 SQLite 的引用,因为 Nuget 包包含适合您的正确版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多