繁体   English   中英

使用SQLite-Net Extensions和OneToMany关系

[英]Using SQLite-Net Extensions and OneToMany relation

我在尝试为Windows Phone 8.1实现具有OneToMany关系的SQLite-Extensions示例时遇到了困难。 我真的很想使用这个功能,但是我正在试着让它发挥作用。 就像在这个问题中一样,当我尝试将提供的示例用于具有Valuations列表的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直接引用。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM