【问题标题】:Azure mobile app and XamarinAzure 移动应用和 Xamarin
【发布时间】:2017-08-04 21:09:33
【问题描述】:

我正在尝试制作一个将使用 Azure 数据库系统的移动应用程序。我在制作自己的表格时遇到了很多麻烦,并且已经在编码圈中运行了几个星期。我只是不知道要改变什么以及如何改变。

我可以从 azure 启动并运行 todolist,并且我尝试使用数据对象和控制器在后端创建自己的表,但是在将 DbSet om 添加到上下文之后,当我尝试时 todolist 部分会中断运行应用程序。

如何将我自己的东西添加到应用程序中,以便我可以有一个人表,而不是 todolist?

提前非常感谢您。这让我很困惑。

这就是我所做的:

在后端,我创建了一个继承 EntityData 类的人员类,并具有一个名字字符串属性和一个姓氏字符串属性 然后我添加了

public DbSet<Person> Persons { get; set; }

然后通过 Add -> Controller -> Azure Mobile 生成 Personcontroller Visual Studio 2017 中的应用表控制器

然后在我从 azure 下载的应用程序中,我创建了 person 类 公共类人 {

    [JsonProperty(PropertyName = "firstName")]
    public string firstName { get; set; }

    [JsonProperty(PropertyName = "lastName")]
    public string lastName { get; set; }

    [JsonProperty(PropertyName = "id")]
    public string id { get; set; }

 }

然后做表

 IMobileServiceTable<Person> PersonTable = client.GetTable<Person>();

然后尝试插入到表中

        Person peter = new Person();
        peter.firstName = "Peter";
        peter.lastName = "Friis";
        await personTable.InsertAsync(peter);

但这给出了错误:

Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: 
'The request could not be completed.  (Internal Server Error)'

【问题讨论】:

  • 请将您尝试过的代码添加到您的帖子中
  • 试过了。有很多代码,因为我使用 Azure 移动应用程序快速入门中的项目。
  • 您解决了这个问题吗,需要进一步的帮助吗?

标签: azure xamarin mobile


【解决方案1】:

根据您的描述,我假设您正在使用带有 SQL 数据库的 C# 后端。我建议您可以在Startup.MobileApp.cs 文件的ConfigureMobileApp 方法下添加以下代码以收集详细的错误消息。

config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

在通过移动客户端 SDK 将新记录插入表之前,您可以利用 postman 或 fiddler 来模拟插入操作,如下所示以缩小此问题:

http表接口的更多细节,可以参考here

此外,由于您要添加自定义表,请确保您已手动更新数据库以支持新的数据库模型或配置自动代码优先迁移。更多细节可以参考adrian hall 的书Implementing Table Controllers

【讨论】:

    猜你喜欢
    • 2020-01-22
    • 2015-10-09
    • 2017-01-03
    • 2017-09-03
    • 1970-01-01
    • 2016-08-24
    • 1970-01-01
    • 2018-06-23
    • 2017-12-16
    相关资源
    最近更新 更多