MS Azure - Bad Request 400

前端 未结 2 1725
予麋鹿
予麋鹿 2021-01-26 02:35

I keep getting a bad request error every time I run this line of code:

List accounts = await App.accountTable.Where(account => account.EmailAdd         


        
相关标签:
2条回答
  • 2021-01-26 02:44

    What does your client-side EmailAddress property look like? It is getting lowercased at some point -- do you have any attributes on it in your client model?

    The reason that 'Username' and 'username' both work is because the server allows both upper-and lower-case with the first letter of properties. For example, 'emailAddress' should work.

    0 讨论(0)
  • 2021-01-26 03:01

    (Can't comment until I have 10 reputation so I'm posting this as an answer..)

    Here is the query request that's generated and sent to the local copy of our database:

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

    which returns this object (I think the "message" property is all that's important):

    {"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)"}
    

    however when modified (by us, in the browser) as follows:

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

    it returns some data.

    When querying the Username field both "Username" and "username" returns data.

    The Account DataObject is defined as:

    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; }
    }
    
    0 讨论(0)
提交回复
热议问题