【问题标题】:GetTable not working for Azure SQL Table(Xamarin Forms)GetTable 不适用于 Azure SQL 表(Xamarin 表单)
【发布时间】:2017-06-05 22:49:55
【问题描述】:

我正在结合我的 Xamarin Forms 移动应用探索 Azure 移动应用服务,并且我已经创建了一个移动应用服务、sql server 和 sql 数据库。

无论如何,经过几个小时后,我被打败了,正在寻求帮助。我在数据库中为我的应用程序创建了一个名为 Person 的基本表,其中包含 Id、FirstName、LastName 列。这些列都是 nvarchar(50) 只是为了方便和测试。我已确认 SQL Server Management Studio 中存在数据库/表,并使用 SSMS 从该表中选择、插入等进行了必要的测试。

根据我所阅读的所有内容,我应该能够执行以下操作并且一切正常:

  1. 将以下内容添加到我的 PersonController 类中:

    public static MobileServiceClient MobileService = new MobileServiceClient("https://somethinghere.azurewebsites.net");
    
  2. 使用 Id、FirstName、LastName 创建一个 Person 类。(所有字符串)

  3. 最后从 Azure 门户添加提供的代码并修改为“Person”,以将数据库连接到现有应用程序:

    //CurrentPlatform.Init();
    Person person = new Person{ Id = "a1", FirstName = "John", LastName = "Doe" };
    await MobileService.GetTable<Person>().InsertAsync(person);
    

注意:该指南说要使用 CurrentPlatform.Init() 但我找不到任何相关信息,即使使用“使用 Microsoft.WindowsAzure.MobileServices;”也会引发错误所以我把它注释掉了。

我试图找出我做错了什么。我收到以下两个错误,似乎与 GetTable 没有返回任何数据有关:

 1. //This is an error I see when I highlight over the breakpoint at the GetTable<Person> line of code
      Could not resolve type: MobileService.GetTable<global::TestAzure.Person  

 2. //This is the exception message returned from a try/catch I added around the code.
      "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." 

【问题讨论】:

    标签: c# sql azure xamarin xamarin.forms


    【解决方案1】:

    CurrentPlatform.Init()

    iOS

    在iOSAppDelegateFinishedLaunching方法中,添加这行代码:

    Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init(); 
    

    Link to sample iOS AppDelegate

    安卓

    在AndroidMainActivityOnCreate方法中,添加这行代码:

    Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
    

    Link to sample Android MainActivity

    【讨论】:

    • 告诉我这是如何工作的,我会根据你的结果更新我的答案!
    • 嘿,这可以解决问题。我目前遇到了 NameResolutionFailure 问题,我认为这意味着我已经解决了这个问题并遇到了另一个问题。老实说,我转而使用 AWS,所以我不会再深入研究这个了。
    猜你喜欢
    • 2020-03-14
    • 2017-12-21
    • 2017-10-01
    • 2023-01-24
    • 2020-11-14
    • 1970-01-01
    • 2018-10-30
    • 1970-01-01
    • 2021-01-15
    相关资源
    最近更新 更多