Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

c# - Sqlite extension is not working as expected

I am working on an WinRT app. I want to use sqlite-net-extensions to support OneToMany, ManyToMany.

using SQLiteNetExtensions.Attributes;
using SQLite;

[Table("WorkFlow")]
public class Workflow
{
    [PrimaryKey, AutoIncrement]
    public int WorkflowId { get; set; }
    public string Name { get; set; }
    public int Revision { get; set; }
    [OneToMany]
    public List<Step> Steps { get; set; }
}

[Table("Step")]
public class Step
{
    public string Type { get; set; }
    public string Description { get; set; }
    [ManyToOne]
    public Workflow Workflow { get; set; }
}

When I try to generate the tables for the database, it raises the exception:

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]

This is coming from the SqlType in SQLite.cs.

But from the example on the sqlite-net-extensions homepage, List property should work fine.

This is a copy of their example:

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

    [OneToMany]      // 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; }
}

Can anyone give me some suggestions to solve this problem? Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is usually an installation issue caused because SQLite-Net Extensions was compiled using a SQLite-Net library but you are running your App using another. You can try adding the PCL NuGet package to your project or you can download the sources from Git and reference the project directly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...