SQLite 扩展例外:多对一关系目标必须具有主键



您可以在标题中看到错误。 有我的表类:

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");

instSQLite.Net.SQLiteConnection实例

当我使用库作为纯代码时,一切正常,但现在我将其添加为 PCL 参考。如您所见,PrimaryKey存在于Models表中。这段代码有什么问题?

这是我在 xamarin 论坛上的帖子。我那里有解决方案。

https://forums.xamarin.com/discussion/comment/288455

最新更新