SQLite 扩展异常:ManyToOne 关系目标必须具有主键
SQLite Extensions exception: ManyToOne relationship destination must have Primary Key
您可以看到标题中的错误。
还有我的table类:
public class Cars : Table
{
[NotNull]
public string name { get; set; }
[ForeignKey(typeof(Models)), NotNull]
public int model_out_id { get; set; }
[ForeignKey(typeof(Bodies)), NotNull]
public int body_out_id { get; set; }
[MaxLength(50)]
public string vin { get; set; }
[MaxLength(4), NotNull]
public int year { get; set; }
[Indexed, NotNull]
public long created_at { get; set; } = DateTime.Now.GetTimestamp();
[ManyToOne(CascadeOperations = CascadeOperation.CascadeRead)]
public Models Model { get; set; }
[ManyToOne(CascadeOperations = CascadeOperation.CascadeRead)]
public Bodies Body { get; set; }
[OneToMany]
public List<CarGlasses> CarGlasses { get; set; }
public Cars()
{
}
}
public class Models : TableLibrary
{
[PrimaryKey, NotNull]
public int out_id { get; set; }
[NotNull]
public string name { get; set; }
[ForeignKey(typeof(Marks)), NotNull]
public int mark_out_id { get; set; }
[Indexed, NotNull]
public int year_from { get; set; }
[Indexed]
public int? year_to { get; set; }
[ManyToOne(CascadeOperations = CascadeOperation.CascadeRead), Ignore]
public Marks Mark { get; set; }
public Models()
{
}
}
此处出现错误:
inst.GetChild(car, "Model");
inst
是 SQLite.Net.SQLiteConnection
实例
当我将库作为纯代码使用时一切正常,但现在我将其添加为 PCL 参考。如您所见,PrimaryKey 存在于 Models
table 中。这段代码有什么问题?
这是我在 xamarin 论坛上的帖子。我有解决办法。
您可以看到标题中的错误。 还有我的table类:
public class Cars : Table
{
[NotNull]
public string name { get; set; }
[ForeignKey(typeof(Models)), NotNull]
public int model_out_id { get; set; }
[ForeignKey(typeof(Bodies)), NotNull]
public int body_out_id { get; set; }
[MaxLength(50)]
public string vin { get; set; }
[MaxLength(4), NotNull]
public int year { get; set; }
[Indexed, NotNull]
public long created_at { get; set; } = DateTime.Now.GetTimestamp();
[ManyToOne(CascadeOperations = CascadeOperation.CascadeRead)]
public Models Model { get; set; }
[ManyToOne(CascadeOperations = CascadeOperation.CascadeRead)]
public Bodies Body { get; set; }
[OneToMany]
public List<CarGlasses> CarGlasses { get; set; }
public Cars()
{
}
}
public class Models : TableLibrary
{
[PrimaryKey, NotNull]
public int out_id { get; set; }
[NotNull]
public string name { get; set; }
[ForeignKey(typeof(Marks)), NotNull]
public int mark_out_id { get; set; }
[Indexed, NotNull]
public int year_from { get; set; }
[Indexed]
public int? year_to { get; set; }
[ManyToOne(CascadeOperations = CascadeOperation.CascadeRead), Ignore]
public Marks Mark { get; set; }
public Models()
{
}
}
此处出现错误:
inst.GetChild(car, "Model");
inst
是 SQLite.Net.SQLiteConnection
实例
当我将库作为纯代码使用时一切正常,但现在我将其添加为 PCL 参考。如您所见,PrimaryKey 存在于 Models
table 中。这段代码有什么问题?
这是我在 xamarin 论坛上的帖子。我有解决办法。