1

Basically I have a Clientclass and an Address class like the following

public class Client
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string Description{ get; set; }
    public string Email { get; set; }
    public string Website { get; set; }
    public string PhoneNumber { get; set; }

    [ForeignKey(typeof(Address))]
    public int AddressId { get; set;}
    [OneToOne(CascadeOperations = CascadeOperation.All)]
    public Address Address { get; set; }
}

public class Address
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string Line1 {get;set;}
    public string Line2 {get;set;}
    public string Line3 {get;set;}
    public string Line4 {get;set;}
    public string Line5 {get;set;}
    public string Line6 {get;set;}
}

I'm using the nuget package SQLite.Net-PCL coupled with the SQLite.Net-PCL Extensions so that I can basically call Insert and pass the Client object to save a client, complete with their address, to the database. Like this:

_db.InsertWithChildren(clientObject);

In my application (Xamarin.iOS with MvvmCross) I have bundled a preexisting database with the application so hence I do not create the tables in code so my point of failure is on the InsertWithChildren(clientObject) call.

I've tried removing the preexisting tables and then creating the tables in code, Address table first and then Client but on create of the Client table it tells me that it "doesn't know" about the Address type/property. The same error if you try the Client table first. I've tried as many variations of this as possible to just save the Client with the Address in a single call but to no avail.

Can anyone shed some light on this?

1 Answers1

1

The problem raises because all the relationship attributes inherit from SQLite-Net Ignore attribute. If you use a different SQLite-Net version it won't recognize the Ignore attribute and it will try to persist the annotated properties, causing it to crash with the error that you are seeing.

Long story short: you are probably using the annotations from one SQLite-Net Extensions and the database connection of the other SQLite-Net version.

If you're using SQLite-Net MvvmCross Community edition you have to use the SQLite-Net Extensions MvvmCross NuGet package, not the PCL one.

redent84
  • 18,901
  • 4
  • 62
  • 85
  • When I installed the MvvmCross two there was an issue with the SQliteConnection class if I remember right. Didn't know how to resolve it so I went back to the PCL two I mention in the question. – codingpitch Nov 07 '14 at 11:52
  • Great, thanks for that! I've no doubt that seems to be the problem I'm experiencing. I even tried explicitly ignoring those properties before but it didn't work either. Can you post that explanation as a response so that others may benefit from it? – codingpitch Nov 07 '14 at 13:05
  • One last thing I would ask is how can I be sure that both the Sqlite.Net and the SqliteNet Extentions are the "matching pair" - because I was aware that if you get the wrong pairing and they won't work but still managed to get tripped up by it. If it isn't too much trouble for you could you tell me which package goes with which in terms of urls for the nuget packages. I'm wanting to get the extensions for this package https://www.nuget.org/packages/SQLite.Net-PCL/. But at this stage I'll accept any working pair and deal with the fallout. – codingpitch Nov 07 '14 at 14:47