Sqlite扩展无法按预期工作

我正在开发一个WinRT应用程序。 我想使用sqlite-net-extensions来支持OneToManyManyToMany

 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 Steps { get; set; } } [Table("Step")] public class Step { public string Type { get; set; } public string Description { get; set; } [ManyToOne] public Workflow Workflow { get; set; } } 

当我尝试为数据库生成表时,它会引发exception:

app_name.exe中出现“System.NotSupportedException”类型的exception但未在用户代码中处理其他信息:不了解System.Collections.Generic.List`1 [app_name.Model.modelName]

这来自SqlType中的SQLite.cs

但是从sqlite-net-extensions 主页上的示例中, List属性应该可以正常工作。

这是他们的例子的副本:

 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 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; } } 

谁能给我一些解决这个问题的建议? 谢谢。

这通常是一个安装问题,因为SQLite-Net Extensions是使用SQLite-Net库编译的,但是您使用另一个运行App。 您可以尝试将PCL NuGet包添加到项目中,也可以从Git下载源代码并直接引用该项目。

尝试为步骤 )提供主键外键引用WorkFlow

 [Table("Step")] public class Step { [PrimaryKey, AutoIncrement] public int StepId { get; set; } [ForeignKey(typeof(WorkFlow))] public int WorkFlowId { get; set; } public string Type { get; set; } public string Description { get; set; } [ManyToOne] public Workflow Workflow { get; set; } } 

修复:从所有项目中卸载对任何SQLite NuGet包的所有引用,在我的例子中,这是一个Xamarin.Forms解决方案。 作为额外的预防措施清理解决方案(您甚至可以检查从packages文件夹中卸载的软件包,以防万一存在阻止删除的文件访问问题)。 通过搜索SQLiteNetExtensions(而不是sqlite-net-pcl)再次安装,并检查在Visual Studio中选择了“Include prerelease”选项(2017年测试)。 这将安装sqlite-net-pcl v1.2.0作为最小依赖项和几个文件,包括单词’Raw’。 您可以在此时测试以检查“不知道System.Collections.Generic.List`1”错误。 对我来说,这消失了。 现在可以安全地将sqlite-net-pcl更新到最新版本,在编写本文时是v1.3.3。

背景:我遇到了以下组合的相同问题:

  1. sqlite-net-pcl v1.3.3
  2. SQLiteNetExtensions v2.0.0-alpha2

在我的第一次尝试中,我首先通过NuGet安装了sqlite-net-pcl,然后安装了SQLiteNetExtensions的最新稳定版本。 在发现扩展名与sqlite-net-pcl不兼容后,我更新到最新的预发布版本。 我遇到了同样的’不知道System.Collections.Generic.List`1’的错误,发现它非常混乱,导致我先尝试其他事情并质疑我是否犯了错误。 清理项目,删除包(从文件夹中)和恢复对我来说不起作用。 我没有检查包配置,但使用NuGet管理器并与测试项目进行比较,一切都是一样的。 卸载我的修复程序中提到的所有内容并让SQLiteNetExtensions为我执行依赖项检查修复了问题。 我认为NuGet文件中存在一个问题,即最初使用错误版本的SQLiteNetExtensions。

PS当天早些时候,NuGet为一个新的Xamarin.Forms项目下载了两个软件包,文件大小为0KB,以典型方式安装,我不得不从另一个项目中复制它们。 我通常不会得到NuGet相关的问题。