从Azure移动服务检索数据

时间:2016-07-01 21:46:42

标签: azure azure-mobile-services

我正在制作一个带有Azure后端的Windows 10应用程序,我开始集成,当我尝试检索数据时,我得到了最奇怪的错误,请参阅下面的代码:

App.xaml.cs中的代码

// Setting up a client to retrieve data, using localhost just to try it out
public static MobileServiceClient DigestsTrackerClient = new MobileServiceClient("http://localhost:28451/");

WeekItem.cs上的代码

// Method to get data from Mobile Services
public static async void GetWeekItems(List<WeekItem> passer)
{
    // Getting a InvalidOperationException down here
    IMobileServiceTable<WeekItem> weekTable = App.DigestsTrackerClient.GetTable<WeekItem>();
    passer = await weekTable.ToListAsync();    
}

有关例外的更多信息:

An exception of type 'System.InvalidOperationException' occurred in 
Microsoft.WindowsAzure.Mobile.dll but was not handled in user code

Additional information: No 'id' member found on type 'TechDigest.Model.WeekItem'.

此外,这是我要检索的对象的模型:

public class WeekItem
{
    public int WeekID { get; set; }
    public string Title { get; set; }
    public string ImageURI { get; set; }
}

这个错误实在令人困惑,因为我基本上从a demo made by an Azure engineer (18:50)复制了代码并且我抛出了这个奇怪的异常,非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

首先,我们建议迁移到Azure Mobile Apps,因为不推荐使用移动服务。

错误告诉您问题 - 您需要客户端上的Id字段。将字符串属性添加到名为Id:

的客户端数据类(在您的案例中为WeekItem

public string Id { get; set; }

您可能也对这些分步教程感兴趣:

相关问题