MS Azure – 错误请求400

每次运行这行代码时,我都会收到错误的请求错误:

List accounts = await App.accountTable.Where(account => account.EmailAddress == email).ToListAsync(); 

这是错误消息:

 A first chance exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.dll Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The request could not be completed. (Bad Request) at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.d__1d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.d__b.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.WindowsAzure.MobileServices.Query.MobileServiceTableQueryProvider.d__8`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.WindowsAzure.MobileServices.Query.MobileServiceTableQueryProvider.d__3`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.WindowsAzure.MobileServices.MobileServiceTableQuery`1.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at eventsphere.Utilities.ValidationUtility.d__2.MoveNext() 

但是我有另一条线基本相同,它工作正常:

 List accounts = await App.accountTable.Where(account => account.Username == username).ToListAsync(); 

我几乎一无所知,为什么一行会给我一个错误而另一行不会,因为所有改变的是我正在查询的Account表的属性。

帐户表结构:(不会让我发布图片,因为我没有足够的声誉)

 CREATE TABLE [eventsphere].[Accounts] ( [Id] NVARCHAR (128) DEFAULT (newid()) NOT NULL, [AccountId] INT IDENTITY (1, 1) NOT NULL, [Username] NVARCHAR (MAX) NULL, [EmailAddress] NVARCHAR (MAX) NULL, [Password] NVARCHAR (MAX) NULL, [IsBusiness] BIT NOT NULL, [User_Id] NVARCHAR (128) NULL, [Business_Id] NVARCHAR (128) NULL, [Version] ROWVERSION NOT NULL, [CreatedAt] DATETIMEOFFSET (7) DEFAULT (sysutcdatetime()) NOT NULL, [UpdatedAt] DATETIMEOFFSET (7) NULL, [Deleted] BIT NOT NULL, CONSTRAINT [PK_eventsphere.Accounts] PRIMARY KEY NONCLUSTERED ([Id] ASC), CONSTRAINT [FK_eventsphere.Accounts_eventsphere.Businesses_Business_Id] FOREIGN KEY ([Business_Id]) REFERENCES [eventsphere].[Businesses] ([Id]), CONSTRAINT [FK_eventsphere.Accounts_eventsphere.Users_User_Id] FOREIGN KEY ([User_Id]) REFERENCES [eventsphere].[Users] ([Id]) ); 

任何输入将不胜感激! 提前致谢 :)

您的客户端EmailAddress属性是什么样的? 它在某些时候变得越来越低 – 你的客户端模型中是否有任何属性?

“用户名”和“用户名”都起作用的原因是服务器允许大写和小写的第一个字母。 例如,’emailAddress’应该有效。

(在我有10个声望之前无法发表评论所以我将此作为答案发布..)

以下是生成并发送到数据库本地副本的查询请求:

 http://localhost:59737/tables/Account?$filter=(emailaddress%20eq%20%27email%40test.com%27) 

返回此对象(我认为“message”属性非常重要):

 {"message":"The query specified in the URI is not valid. Could not find a property named 'emailaddress' on type 'eventsphereService.DataObjects.Account'.","exceptionMessage":"Could not find a property named 'emailaddress' on type 'eventsphereService.DataObjects.Account'.","exceptionType":"Microsoft.Data.OData.ODataException","stackTrace":" at Microsoft.Data.OData.Query.EndPathBinder.GeneratePropertyAccessQueryForOpenType(EndPathToken endPathToken, SingleValueNode parentNode)\r\n at Microsoft.Data.OData.Query.EndPathBinder.BindEndPath(EndPathToken endPathToken, BindingState state)\r\n at Microsoft.Data.OData.Query.MetadataBinder.BindEndPath(EndPathToken endPathToken)\r\n at Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken token)\r\n at Microsoft.Data.OData.Query.BinaryOperatorBinder.GetOperandFromToken(BinaryOperatorKind operatorKind, QueryToken queryToken)\r\n at Microsoft.Data.OData.Query.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n at Microsoft.Data.OData.Query.MetadataBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n at Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken token)\r\n at Microsoft.Data.OData.Query.FilterBinder.BindFilter(QueryToken filter)\r\n at Microsoft.Data.OData.Query.ODataUriParser.ParseFilterImplementation(String filter, IEdmType elementType, IEdmEntitySet entitySet)\r\n at System.Web.Http.OData.Query.FilterQueryOption.get_FilterClause()\r\n at System.Web.Http.OData.Query.Validators.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)\r\n at System.Web.Http.OData.Query.FilterQueryOption.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.Http.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n at System.Web.Http.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.Http.OData.EnableQueryAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)\r\n at System.Web.Http.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)\r\n at System.Web.Http.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"} 

但是当我们在浏览器中修改时如下:

 http://localhost:59737/tables/Account?$filter=(EmailAddress%20eq%20%27email%40test.com%27) 

它返回一些数据。

查询用户名字段时,“用户名”和“用户名”都返回数据。

Account DataObject定义为:

 public class Account : EntityData { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int AccountId { get; set; } public string Username { get; set; } [DataType(DataType.EmailAddress)] public string EmailAddress { get; set; } public string Password { get; set; } public bool IsBusiness { get; set; } public string User_Id { get; set; } [DatabaseGenerated(DatabaseGeneratedOption.None)] [ForeignKey("User_Id")] [Association("UserIdAssociation", "UserId", "Id")] [Column(Order = 1)] public virtual User User { get; set; } public string Business_Id { get; set; } [DatabaseGenerated(DatabaseGeneratedOption.None)] [ForeignKey("Business_Id")] [Association("BusinessIdAssociation", "BusinessId", "Id")] public virtual Business Business { get; set; } }