SQLite Extensions异常:ManyToOne关系目标必须具有主键

时间:2017-07-25 15:09:10

标签: android sqlite xamarin sqlite-net sqlite-net-extensions

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

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引用。正如您所见,Models表中存在PrimaryKey。这段代码有什么问题?

1 个答案:

答案 0 :(得分:0)

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

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