jeudi 15 janvier 2015

Xamarin - SQLite - How to get rid of mismatch exception with Guid

I continue to get an SQLite exception ... 'Mismatch' on the line sqliteConn.Insert (uniqueDeviceToAdd);


I'm trying to add a GUID to the database that I can basically use to track installs. So I want to store the GUID on the device if it doesn't have an entry in the UniqueDevice table, or retrieve it if it does.


I have tried storing the Guid as a string and using .ToString() but I still get the same error.


Thanks...



string folder = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
var sqliteConn = new SQLiteConnection (System.IO.Path.Combine (folder, "TEST.db"));
Guid uniqueId;
if (sqliteConn.Table<UniqueDevice> ().Count() == 0) {
uniqueId = Guid.NewGuid();
var uniqueDeviceToAdd = new UniqueDevice {
UniqueDeviceID = uniqueId
};
sqliteConn.Insert (uniqueDeviceToAdd);
} else {
uniqueId = sqliteConn.Table<UniqueDevice> ().FirstOrDefault ().UniqueDeviceID;
}




public class UniqueDevice
{
[PrimaryKey]
public Guid UniqueDeviceID { get; set; }
}


I've also tried totally deleting the tables etc. to no avail


Aucun commentaire:

Enregistrer un commentaire