Linq和SQL Azure的行为

时间:2017-07-01 03:51:50

标签: linq xamarin.forms azure-sql-database azure-web-sites azure-mobile-services

我正在创建一个新的Xamarin Forms应用程序,并使用连接到SQL Azure数据库的Azure移动应用程序。

这是我用来查询表格的代码:

IEnumerable<Club> clubs = await (from club in ClubManager.DefaultManager.ClubTable.CreateQuery()
                          where club.Nom.Contains(TexteRecherche)
                          select club).ToEnumerableAsync();

我随机获得以下异常:

The exception
Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException occurred
  HResult=0x80131509
  Message=The request could not be completed.  (Bad Request)    
  Source = <Unable to evaluate the source of the exception>
  Procedural Call Tree:
   à Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<ThrowInvalidResponse>d__24.MoveNext()
   à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   à Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<SendRequestAsync>d__26.MoveNext()
   à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   à Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<RequestAsync>d__18.MoveNext()
   à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   à Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<ReadAsync>d__20.MoveNext()
   à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   à Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<ReadAsync>d__18.MoveNext()
   à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   à Microsoft.WindowsAzure.MobileServices.Query.MobileServiceTableQueryProvider.<Execute>d__8`1.MoveNext()
   à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   à Microsoft.WindowsAzure.MobileServices.Query.MobileServiceTableQueryProvider.<Execute>d__7`1.MoveNext()
   à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   à System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   à EagleGolf.CourseEditor.ViewModels.MainPageViewModel.<LitClubs>d__23.MoveNext() dans D:\Julien\MobileApps\EagleGolf.CourseEditor\EagleGolf.CourseEditor\EagleGolf.CourseEditor\ViewModels\MainPageViewModel.cs :ligne 107
build : `

这很奇怪,因为我关闭并重新启动应用程序并再次运行。它可以工作2-3次,然后停止工作,然后再次工作。

我的数据库只包含1个表,此表只包含2个记录...

1 个答案:

答案 0 :(得分:0)

IEnumerable<Club> clubs = await (from club in ClubManager.DefaultManager.ClubTable.CreateQuery()
                      where club.Nom.Contains(TexteRecherche)
                      select club).ToEnumerableAsync();

对于IMobileServiceTable表,上述查询会针对您的移动应用后端发送以下请求:

Get https://{your-app-name}.azurewebsites.net/tables/{table-name}?$filter=substringof('{TexteRecherche}',Nom)
  

消息=无法完成请求。 (错误请求

我认为您可以利用Fiddler并在调用相关查询时检查您的代码,如下所示:

enter image description here