使用SQLite Net扩展和OneToMany关系

本文关键字:OneToMany 关系 扩展 SQLite Net 使用 | 更新日期: 2023-09-27 18:29:47

我很难为Windows Phone 8.1实现一个具有OneToMany关系的SQLite扩展示例。我真的很想使用这个功能,但我正在努力让它发挥作用。就像在这个问题中一样,当我尝试使用所提供的具有估价列表的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直接引用。

我已经在我的解决方案中本地包含了源代码,这似乎没有什么区别。有人有什么进一步的建议吗?我还没有找到任何可下载的例子。

使用SQLite Net扩展和OneToMany关系

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