【问题标题】:Retrieving data from Azure Mobile Services从 Azure 移动服务检索数据
【发布时间】:2016-07-06 06:17:14
【问题描述】:

我正在使用我开始集成的 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) 复制代码而我的抛出了这个奇怪的异常,非常感谢任何帮助。

【问题讨论】:

    标签: azure azure-mobile-services


    【解决方案1】:

    首先,我们建议迁移到 Azure Mobile Apps,因为移动服务已被弃用。

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

    public string Id { get; set; }

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

    【讨论】:

    • 值得尝试解决吗?既然你说它相当先进?如何在客户端添加 Id 字段?您的意思是向我的对象(WeekItem)添加一个“Id”字符串?如果我切换到 Azure 移动应用,这种情况还会发生吗?
    • 是的——你在你的 WeekItem 类中添加了“public string Id { get; set; }”。这将解决问题。是的,当您切换到 Azure 移动应用时,它仍然会发生。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多