I'm using Visual Studio 2017, new to SQLite and can't get my head behind how I get to access the values saved in the database and get it back to the elements of the class.
public class MyObject
{
[PrimaryKey, AutoIncrement]
public int IndexNumber
{get;set;}
[MaxLength(20)]
public int SomeID
{get;set;}
[MaxLength(70)]
public string SomeName
{get; set;}
[MaxLength(25)]
public string Telephone
{get; set;}
public DateTime someTime
{get; set;}
//...some more data
}
public class MyDB
{
readonly SQLiteAsyncConnection database;
public MyDB (string dbPath);
database.CreateTableAsync<MyObject>().Wait();
public Task<List<MyObject>> GetMyObjectAsync()
{
return database.Table<MyObject>().ToListAsync();
}
public Task<MyObject> GetSingleObjectAsync(int ind)
{
return database.Table<MyObject>().Where(i => i.IndexNumber == ind).FirstOrDefaultAsync();
}
public Task<int> SaveMyObjectAsync(MyObject object)
{
if (object.IndexNumber == 0)
{
return database.InsertAsync(object)
}
else
{
return database.UpdateAsync(object);
}
}
public Task<int> DeleteMyObjectAsync(MyObject object)
{
return database.DeleteAsync(object);
}
}
Inputting data through the .xaml pages works without any problems so far, selecting the object in ListView works as well.
The problem now is that I just can't seem to find a proper way to convert the returned Task back to an object to update some of those values with data only supplied through a HTTP response which itself does not always supply all the data for the datatable, e.g. only the ID and a code if it was successful in the first response. It then needs other data from the object and again delivers values for different elements of the object which is why I'd like to know if there was some method to get a row of data back to a temporary object to update it in the database, remove it if needed (canceled through the HTTP response) or modify it.