ios - Xamarin/IOS/Azure - 在类型上找不到 'id' 成员

标签 ios azure asynchronous xamarin offline

我有一个用 Xamarin Android 开发的应用程序,并且运行良好。 我正在执行 IOS Xamarin 版本,但在激活异步 Offline Azure 时遇到问题。 在模拟器工作时testo设备产生以下错误。

“在‘FM.Model.Categoria’类型中找不到‘id’成员。”

using Microsoft.WindowsAzure.MobileServices;
using Microsoft.WindowsAzure.MobileServices.SQLiteStore;
using Microsoft.WindowsAzure.MobileServices.Sync;
using System;
using System.IO;
using System.Threading.Tasks;

namespace FM.Dados
{
    public class AtualizaDados
    {
        static AtualizaDados instance = new AtualizaDados();

        const string applicationURL = @"https://xxxx.azurewebsites.net";

        private MobileServiceClient client;
        private IMobileServiceSyncTable<Model.Categoria> categoriaTable;

        private AtualizaDados()
        {
            try
            {
                CurrentPlatform.Init();
                SQLitePCL.CurrentPlatform.Init();

                // Initialize the Mobile Service client with the Mobile App URL, Gateway URL and key
                client = new MobileServiceClient(applicationURL);

                // Create an MSTable instance to allow us to work with the TodoItem table
                categoriaTable = client.GetSyncTable<Model.Categoria>();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(@"Sync Failed: {0}", e.Message);
            }
        }

        public static AtualizaDados DefaultService
        {
            get
            {
                return instance;
            }
        }

        public async Task InitializeStoreAsync()
        {
            try
            {
                var store = new MobileServiceSQLiteStore(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "fm.db"));
                store.DefineTable<Model.Categoria>();

                await client.SyncContext.InitializeAsync(store);
            }
            catch(Exception e)
            {
                Console.Error.WriteLine(@"Sync Failed: {0}", e.Message);
            }
        }

        public async Task SyncAsync(bool pullData = false)
        {
            try
            {
                await client.SyncContext.PushAsync();

                if (pullData)
                {
                    await categoriaTable.PullAsync("allCategoria", categoriaTable.CreateQuery());
                }
            }

            catch (MobileServiceInvalidOperationException e)
            {
                Console.Error.WriteLine(@"Sync Failed: {0}", e.Message);
            }
        }
    }
}

属性“Id ”存在,但仍然出现错误。

using Newtonsoft.Json;

namespace FM.Model
{
    public class Categoria
    {
        public string Id { get; set; }

        [JsonProperty(PropertyName = "Codigo")]
        public int Codigo { get; set; }

        [JsonProperty(PropertyName = "Nome")]
        public string Nome { get; set; }

        public bool Deleted { get; set; }
    }

}

我查看了多个用户论坛,都出现了相同的错误,但没有解决方案可以解决我的问题。 有人知道会发生什么吗? 由于模拟器可以工作,我需要一些许可吗?

最佳答案

看起来您没有在获取 SyncTable 之前定义存储。这里需要一个自然的顺序:

  1. 创建客户端
  2. 使用 DefineTable 生成本地商店 map
  3. 初始化商店
  4. 获取同步表。

试试这个:

        try
        {
            CurrentPlatform.Init();
            SQLitePCL.CurrentPlatform.Init();

            // Initialize the Mobile Service client with the Mobile App URL, Gateway URL and key
            client = new MobileServiceClient(applicationURL);

            // Initialize the local offline store
            await InitializeStoreAsync();

            // Create an MSTable instance to allow us to work with the TodoItem table
            categoriaTable = client.GetSyncTable<Model.Categoria>();
        }

关于ios - Xamarin/IOS/Azure - 在类型上找不到 'id' 成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39455843/

相关文章:

ios - react native : Pass target Location onPress to google maps or ios maps and execute a GPS Navigation towards said target

wcf - 通过附加到请求线程的安全主体访问声明,而不是 AuthorizationContext

mongodb - Azure SQL API 与 Azure Mongo API

c# - 异步等待最佳实践

python - 通过异步 websocket 客户端与 websocket 服务器保持连接

c# - 异步方法签名错误。必须返回 void、Task 或 Task<T>

ios - 是否可以保存对照片库中照片存储位置的引用,而不是将实际的 UIImage 本身保存为数据?

iphone - Receiver type() for instance message 是 ARC 中的前向声明问题

ios - viewForSupplementaryElementOfKind 没有被调用

node.js - Visual Studio代码: Deploy to azure appears to work but no files seem to transfer