几天后,我一直在使用Parse.com
将数据同步到云端。我现在正在编写所有函数来从云中获取所有数据并将其与本地SQLite
数据库同步。
我使用ParseObject
从云中获取所有数据:
var taskQuery = from TaskTable in ParseObject.GetQuery("Task")
where TaskTable.Get<Boolean>("Deleted") == false
where TaskTable.Get<DateTime>("updatedAt") > SqliteSyncDate
select TaskTable;
IEnumerable<ParseObject> tasks = await taskQuery.FindAsync();
将其放入ParseObject
后,我用foreach
循环播放,但我遇到了问题。我有一个表Task
,其中有一个字段UserId
,我将其定义为表Pointer
的{{1}}。我现在必须将此Login
存储在我的SQLite数据库中,但我不知道如何解析&#39;和/或现在在本地保存。
我的代码:
Pointer
如果我在没有try catch的情况下运行它,我将收到以下错误:
//Loop over every record that is returned from Parse.com
foreach (ParseObject task in tasks)
{
try
{
//Create new record to add to Task
Tasks taskSqlite = new Tasks();
taskSqlite.Id = task.Get<int>("Id");
//This line fails! When I comment it out syncing works, otherwise it doesn't.
taskSqlite.UserId = task.Get<int>("UserId");
taskSqlite.Description = task.Get<string>("Description");
taskname = task.Get<string>("Description");
taskSqlite.Date = task.Get<DateTime?>("Date");
taskSqlite.Done = task.Get<Boolean>("Done");
taskSqlite.DoneBy = task.Get<string>("DoneBy");
taskSqlite.Deleted = task.Get<Boolean>("Deleted");
taskSqlite.LastModified = task.Get<DateTime?>("LastModified");
//And finally insert the record in to the SQLite database.
DATask.InsertTask(taskSqlite);
}
catch
{
Debug.WriteLine("SYNC FAILURE - failed on table Task on the task: " + taskname);
}
更新:正如我所指出的,我决定也打印Exception。这是例外:
03-31 16:37:52.676 I/MonoDroid( 4731): UNHANDLED EXCEPTION:
03-31 16:37:52.697 I/MonoDroid( 4731): System.NullReferenceException: Object reference not set to an instance of an object
然后我创建了一个Exception: System.InvalidCastException: Value is not a convertible object:
Parse.ParseObject to System.Int32
03-31 17:03:18.335 I/mono-stdout( 8270): SYNC FAILURE - failed on table Task
on the task: Exception: System.InvalidCastException: Value is not a
convertible object: Parse.ParseObject to System.Int32
[0:] SYNC FAILURE - failed on table Task on the task: Exception:
System.InvalidCastException: Value is not a convertible object:
Parse.ParseObject to System.Int32
at System.Convert.ToType (System.Object value, System.Type conversionType,
IFormatProvider provider, Boolean try_target_to_type) [0x00000] in <filename
unknown>:0
at System.Convert.ChangeType (System.Object value, System.Type
conversionType) [0x00000] in <filename unknown>:0
at Parse.ParseClient.ConvertTo[Int32] (System.Object value) [0x00000] in
<filename unknown>:0
at Parse.ParseObject.Get[Int32] (System.String key) [0x00000] in <filename
unknown>:0
。但是,我现在怎样才能将UserId从中获取?
ParseRelation
那么我应该如何转换它或将其保存到SQLite数据库中呢?这是将记录链接到彼此的正确方法吗?
答案 0 :(得分:0)
似乎你遇到int类型的问题。也许尝试Int32或其他什么?如果这没有帮助,您可以检查数据库中的值。也许UserId不是可以转换为int的数值?
答案 1 :(得分:0)
对不起,迟到的回复
presentViewController
应该做的伎俩