0

Microsoft が提供する 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、次のように 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'."}

しばらくの間、これを修正しようとしていますが、何が問題なのかわかりません。

4

1 に答える 1