简体   繁体   English

使用SQLite-Net Extensions和OneToMany关系

[英]Using SQLite-Net Extensions and OneToMany relation

I'm having difficulty trying to implement an SQLite-Extensions example for Windows Phone 8.1 that features a OneToMany relation. 我在尝试为Windows Phone 8.1实现具有OneToMany关系的SQLite-Extensions示例时遇到了困难。 I'd really like to use this feature but I'm pulling my hair out trying to get it to work. 我真的很想使用这个功能,但是我正在试着让它发挥作用。 Like in this question , when I try to use the provided example for a Stocks table that has a List of Valuations: 就像在这个问题中一样,当我尝试将提供的示例用于具有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; }
}

and I try to create the table I get the error: 我尝试创建表我得到错误:

An exception of type 'System.NotSupportedException' occurred in app_name.exe but was not handled in user code Additional information: Don't know about >System.Collections.Generic.List`1 [app_name.Model.modelName] app_name.exe中发生类型为“System.NotSupportedException”的异常但未在用户代码中处理附加信息:不知道> System.Collections.Generic.List`1 [app_name.Model.modelName]

I had initially included a NuGet package reference to sqlite-net as well as SQLiteNetExtensions-PCL but it was previously mentioned that this is due to the wrong version of sqlite-net being referenced. 我最初包含了对sqlite-net以及SQLiteNetExtensions-PCL的NuGet包引用,但之前提到过这是由于引用了错误版本的sqlite-net。

However I've tried downloading the source for sqlite-net and building this locally and it doesn't get referenced directly by SQLiteNetExtensions. 但是我已经尝试下载sqlite-net的源代码并在本地构建它并且它不会被SQLiteNetExtensions直接引用。

I've included the source locally in my solution as well it doesn't seem to make a difference. 我已经在我的解决方案中本地包含了源代码,它似乎没有什么区别。 Would anybody have any further suggestions? 有人会有进一步的建议吗? I haven't come across any downloadable example for this. 我没有遇到任何可下载的示例。

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

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

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