mardi 15 septembre 2015

Using Textblobbed in sqlite-net-extensions

I'm trying to map a complex class in sqlite but something seems to be wrong because when I retrieve my objects the complex fields are empty. Shortly, my class is something similar:

 public class Contact
 {
    [PrimaryKey, AutoIncrement]
    public int Id { set; get; }
    public string Name { set; get; }
    public string Status { set; get; }

    [TextBlob("PhoneNumbersBlobbed")]
    public List<PhoneNumber> PhoneNumbers { set; get; }
    public string PhoneNumbersBlobbed { get; set; } // serialized PhoneNumbers

    [TextBlob("MailAddressesBlobbed")]
    public List<ContactEmail> MailAddresses { set; get; }
    public string MailAddressesBlobbed { get; set; } // serialized MailAddresses
 }

I obviously have a separated class for PhoneNumber:

     public class PhoneNumber
     {          
        public string Number { set; get; }
        public bool IsVerified { set; get; }
        public string AttrString { set; get; }  
    }

while ContactEmail class is a native class of WinPhone.

Well, after have created the tables in DB:

 connection.CreateTable<Contact.PhoneNumber>();
 connection.CreateTable<Contact>();

and have populated my List of Contact I save them in DB. I tried as saving one by one with:

connection.InsertWithChildren(contact,true);

as all the list togheter:

connection.InsertAllWithChildren(listOfContacts, true);

and I'm sure that the list is correctly populated before to save it. But when I read its values from sqlite:

var list = connection.Table<Contact>().ToList();
connection.UpdateAll(list ,true);

I can't see values in my PhoneNumbers and MailAddresses fields, while they are filled with serialized value in their blobbed fields.

In addiction, trying to manually deserialize the blobbed fields, I get an exception from Json.net (ie. doing in this way):

 foreach (Contact pc in list)
        {
            try
            {
                Contact.PhoneNumber[] numbs = JsonConvert.DeserializeObject<PhoneContact.PhoneNumber[]>(pc.PhoneNumbersBlobbed);
            }
            catch {
                ;
            }
        }

what am I wrong? Thank you

Aucun commentaire:

Enregistrer un commentaire