【问题标题】:SQLite Extensions exception: ManyToOne relationship destination must have Primary KeySQLite 扩展异常:ManyToOne 关系目标必须具有主键
【发布时间】:2017-07-25 15:09:10
【问题描述】:

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

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 表中。这段代码有什么问题?

【问题讨论】:

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


    【解决方案1】:

    这是我在 xamarin 论坛上的帖子。我有解决办法。

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

    【讨论】:

      猜你喜欢
      • 2019-02-13
      • 2021-12-17
      • 1970-01-01
      • 2010-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 2011-03-02
      相关资源
      最近更新 更多