【发布时间】:2017-07-21 18:32:00
【问题描述】:
我正在开发一个 WinRT 应用程序。我想用sqlite-net-extensions来支持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; }
}
当我尝试为数据库生成表时,它会引发异常:
“System.NotSupportedException”类型的异常发生在 app_name.exe 但未在用户代码中处理其他信息: 不知道 System.Collections.Generic.List`1 [app_name.Model.modelName]
这是来自SQLite.cs 中的SqlType。
但从sqlite-net-extensions homepage 的示例来看,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<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; }
}
谁能给我一些解决这个问题的建议?谢谢。
【问题讨论】:
-
我遇到了完全相同的问题,SQLite.cs 类型解析方法:
string SqlType(TableMapping.Column p, bool storeDateTimeAsTicks)没有对 List 类型的解释,因此它会抛出 NotSupportedException。我尝试使用 nuget 并添加 SQLiteNetExtensions 的源(及其参考)但没有运气......有人吗? -
您找到解决方案了吗?我遇到了同样的问题
-
没关系,@redent84 给出了答案。
标签: c# windows-runtime windows-store-apps sqlite-net sqlite-net-extensions