Retrieving data from Azure Mobile Services

浪尽此生 提交于 2019-12-12 01:37:17

问题


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:

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/");

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; }
}

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.


回答1:


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

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


来源:https://stackoverflow.com/questions/38154246/retrieving-data-from-azure-mobile-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!