我按照微软在此处提供的 Windows Azure 移动服务指南进行操作。
我创建了一个category
代表类别表的类,如下所示:
public class category
{
public int Id { get; set; }
//// TODO: Add the following serialization attribute.
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
//// TODO: Add the following serialization attribute.
[JsonProperty(PropertyName = "subscribers")] //Number of Subscribers
public int Subscribers { get; set; }
[JsonProperty(PropertyName = "posts")] //Number of posts inside this category
public int Posts { get; set; }
}
然后我在数据库中插入了一个条目,如下所示:
private IMobileServiceTable<category> categoryTable = App.MobileService.GetTable<category>();
category temp = new category() { Name = "test", Posts = 1, Subscribers = 2 };
await categoryTable.InsertAsync(temp);
直到这里一切都很好。然后我创建了一个users
类来表示用户表,如下所示:
class users
{
public int Id { get; set; } //the generated ID by the mobile service.
//// TODO: Add the following serialization attribute.
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
//// TODO: Add the following serialization attribute.
[JsonProperty(PropertyName = "nusnet")]
public string NUSNET { get; set; }
[JsonProperty(PropertyName = "email")]
public string Email { get; set; }
[JsonProperty(PropertyName = "faculty")]
public string Faculty { get; set; }
}
现在,当我尝试添加用户时:
await userTable.InsertAsync(loggedInUser);
其中登录用户是用户的详细信息。如指南中所述,我将 Id 字段留空,在调试期间我注意到 Id 设置为 0。
我收到一个错误:
NewtonSoft.JSON.JsonSerializationException: {"Error getting value from 'Id' on 'NUSocial.users'."}
我一直在尝试解决这个问题,但我不知道出了什么问题。