SQLite扩展异常:ManyToOne关系目标必须具有主键
问题描述:
您可以在标题中看到错误。 有我的表类:发生SQLite扩展异常:ManyToOne关系目标必须具有主键
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参考。正如您可以看到在Models
表中存在PrimaryKey。这段代码有什么问题?