I followed the Windows Azure mobile service guide given by Microsoft over here.
I create a category
class which represented the category table as follows:
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; }
}
I then inserted an entry into the database as give:
private IMobileServiceTable<category> categoryTable = App.MobileService.GetTable<category>();
category temp = new category() { Name = "test", Posts = 1, Subscribers = 2 };
await categoryTable.InsertAsync(temp);
All worked fine till here. Then i created a users
class to represent the users table as follows:
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; }
}
Now when I try to add in a user:
await userTable.InsertAsync(loggedInUser);
where logged in user is the details of the user. As given in the guide, i leave the Id filed empty and during debugging I notice that the Id is set as 0.
I get an error:
NewtonSoft.JSON.JsonSerializationException: {"Error getting value from 'Id' on 'NUSocial.users'."}
I have been trying fixing this for a while now but I have no clue on what is going wrong.
public class users
instead of what you currently have). – carlosfigueira