我正在结合我的 Xamarin Forms 移动应用探索 Azure 移动应用服务,并且我已经创建了移动应用服务、sql server 和 sql 数据库。
无论如何,经过几个小时后,我已经被打败了,正在寻求一些帮助。我在数据库中为我的应用程序创建了一个名为 Person 的基本表,其中包含 Id、FirstName、LastName 列。这些列都是 nvarchar(50) 只是为了方便和测试。我已确认 SQL Server Management Studio 中存在数据库/表,并使用 SSMS 从该表中进行了选择、插入等必要的测试。
从我读过的所有内容来看,我应该能够执行以下操作并让一切正常工作:
将以下内容添加到我的 PersonController 类中:
public static MobileServiceClient MobileService = new MobileServiceClient("https://somethinghere.azurewebsites.net");
使用 Id、FirstName、LastName 创建一个 Person 类(所有字符串)
最后从 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 AppDelegate
的 FinishedLaunching
方法中,添加以下代码行:
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
Link to sample iOS AppDelegate
安卓
在 Android MainActivity
的 OnCreate
方法中,添加以下代码行:
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
关于c# - GetTable 不适用于 Azure SQL 表(Xamarin Forms),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41772272/