从Azure移动服务检索数据 [英] Retrieving data from Azure Mobile Services

查看:60
本文介绍了从Azure移动服务检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am making a Windows 10 app with an Azure backend which I started to integrate and when I try to retrieve data I am getting the most odd error, please see code below:

App.xaml.cs中的代码

Code in 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上的代码

Code on 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();    
}

有关该异常的更多信息:

More information on the exception:

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'.

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

Also, here is the model for the object that I am trying to retrieve:

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

此错误确实令人迷惑,因为我基本上是从 Azure工程师制作的演示中复制代码的(18 :50),而我抛出了这个怪异的异常,我们将不胜感激.

This error really confusing since I basically copied the code from a demo made by an Azure engineer (18:50) and mine throws this weird exception, any help is greatly appreciated.

推荐答案

首先,我们建议迁移到

First, we recommend migrating to Azure Mobile Apps, since Mobile Services is deprecated.

该错误告诉您问题所在-您需要在客户端上提供一个ID字段.向您的客户端数据类(在您的情况下为WeekItem)添加一个称为Id的字符串属性:

The error tells you the issue--you need an Id field on the client. Add a string property to your client data class (WeekItem in your case) called Id:

public string Id { get; set; }

您可能还对以下分步教程感兴趣:

You might also be interested in these step-by-step tutorials:

  • Create a Windows app with Azure Mobile Apps
  • Add authentication to your Windows app
  • Enable offline sync for your Windows app

这篇关于从Azure移动服务检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆