我有一个用 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 之前定义存储。这里需要一个自然的顺序:
- 创建客户端
- 使用 DefineTable 生成本地商店 map
- 初始化商店
- 获取同步表。
试试这个:
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/