简体   繁体   中英

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. 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:

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]

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.

However I've tried downloading the source for sqlite-net and building this locally and it doesn't get referenced directly by 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包中包含正确的版本。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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