为了简单起见,我遇到的所有使用 Azure 移动服务的示例应用程序和代码都没有遵循 MVVM 模式。
如何编写一个 MVVM 应用程序,该应用程序使用 Azure 移动服务访问云中的数据,然后将数据缓存在 Windows 手机本地数据库(模型)中。我现有的模型类是这样的 -
[Table]
public class ToDoItem
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int ToDoItemId
{
...
}
[Column]
public string ItemName
{
...
}
[Column]
public bool IsComplete
{
...
}
}
现在我想在云中处理这些数据,示例告诉我,我需要像这样构建我的类 -
public class TodoItem
{
public string Id { get; set; }
[JsonProperty(PropertyName = "text")]
public string Text { get; set; }
[JsonProperty(PropertyName = "complete")]
public bool Complete { get; set; }
}
这如何适应 MVVM 模式?我的模型类需要是什么样的。我是否使用两个版本的 ToDoItem 类,一个用于从本地数据库设置/获取数据,另一个用于从云设置/获取数据以及将一个转换为另一个的东西?有没有人可以指点我的样本?