SQLite Extensions exception: ManyToOne relationship destination must have Primary Key

You can see the error in title. There are my table classes:

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()
    {
    }
}

Error occurs here:

inst.GetChild(car, "Model");

inst is SQLite.Net.SQLiteConnection instance
Everything worked fine when I used library as plain code, but now I added it as PCL reference. As you can see PrimaryKey exists in Models table. What's wrong with this code?

Best Answer

  • DirkWilhelmDirkWilhelm US ✭✭✭✭
    edited July 2017 Accepted Answer

    @Nikita_Leshchev

    Ok, you are using the latest stable 1.3.0. Try updating that to the 2.0.0-alpha2.

    Aditionally, but not related to your problem: you have both SQLite.Net-PCL and sqlite-net-pcl in your project. You don't need both, get rid of one.

    Personally i use sqlite-net-pcl 1.3.1 in combination with SQLiteNetExtensions.Async 2.0.0-alpha2

Answers

Sign In or Register to comment.