c# - GetTable 不适用于 Azure SQL 表(Xamarin Forms)

标签 c# sql azure xamarin xamarin.forms

我正在结合我的 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() 但我找不到任何相关信息,即使使用“using 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." 

最佳答案

CurrentPlatform.Init()

iOS

在 iOS AppDelegateFinishedLaunching 方法中,添加以下代码行:

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

Link to sample iOS AppDelegate

安卓

在 Android MainActivityOnCreate 方法中,添加以下代码行:

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

Link to sample Android MainActivity

关于c# - GetTable 不适用于 Azure SQL 表(Xamarin Forms),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41772272/

相关文章:

mysql - 在连接字段中选择/搜索

azure - 自定义 STS 和 Azure ACS 错误 ACS50008 : Invalid SAML token

C# 检测击键并发送到后台窗口

c# - 调用任何方法时 "=>"运算符和 {} 有什么区别?

c# - 了解 C# 中的非托管关键字

c# - 无法建立连接,因为目标机器主动拒绝 127.0.0.1 :8000

mysql - 确定什么是向 mysql 表中插入空白行?

sql - 获取 PostgreSQL 中受 INSERT 或 UPDATE 影响的记录数

azure - 如何以编程方式在 Azure AD 中添加自定义域名?

wcf - 配置在 Azure Web 角色上启用 HTTPS WCF Web 服务