Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OData $select throws QuerySyntaxException #2498

Closed
fairking opened this issue Aug 25, 2020 · 4 comments
Closed

OData $select throws QuerySyntaxException #2498

fairking opened this issue Aug 25, 2020 · 4 comments

Comments

@fairking
Copy link

NHibenrate v. 5.3.2
Microsoft.AspNetCore.OData v. 7.4.1
.Net Core 3.1

Url:
https://localhost:5001/odata/weatherforecast?$select=Town
https://localhost:5001/odata/weatherforecast?$select=Town2

The actual error:

NHibernate: select weatherfor0_.date as col_0_0_, weatherfor0_.id as col_1_0_, weatherfor0_.summary as col_2_0_, weatherfor0_.temperature_c as col_3_0_, cast(weatherfor0_.temperature_c as DOUBLE) as col_4_0_, town1_.name as col_5_0_, town1_.name as col_6_0_ from weather_forecast weatherfor0_ left outer join town town1_ on weatherfor0_.town_id=town1_.id
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HM28QED9SQF2", Request id "0HM28QED9SQF2:00000003": An unhandled exception was thrown by the application.
NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: A recognition error occurred. [.Select[NhOdataTest.ViewModels.WeatherForecastVm, NhOdataTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null,Microsoft.AspNet.OData.Query.Expressions.SelectExpandBinder+SelectSome`1[[NhOdataTest.ViewModels.WeatherForecastVm, NhOdataTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Microsoft.AspNetCore.OData, Version=7.4.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35](.Select[NhOdataTest.Entities.WeatherForecast, NhOdataTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null,NhOdataTest.ViewModels.WeatherForecastVm, NhOdataTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null](.Fetch[NhOdataTest.Entities.WeatherForecast, NhOdataTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null,NhOdataTest.Entities.Town, NhOdataTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null](NHibernate.Linq.NhQueryable`1[NhOdataTest.Entities.WeatherForecast], Quote((x, ) => (x.Town)), ), Quote((dtoWeatherForecast, ) => (new NhOdataTest.ViewModels.WeatherForecastVm, NhOdataTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null()dtoWeatherForecast.DatedtoWeatherForecast.IddtoWeatherForecast.SummarydtoWeatherForecast.TemperatureCAdd(p1, Convert(Divide(Convert(dtoWeatherForecast.TemperatureC), p2)))dtoWeatherForecast.Town.NamedtoWeatherForecast.Town.Name)), ), Quote(($it, ) => (new Microsoft.AspNet.OData.Query.Expressions.SelectExpandBinder+SelectSome`1[[NhOdataTest.ViewModels.WeatherForecastVm, NhOdataTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Microsoft.AspNetCore.OData, Version=7.4.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35()p3new Microsoft.AspNet.OData.Query.Expressions.PropertyContainer+NamedProperty`1[[System.Nullable`1[[System.Guid, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], Microsoft.AspNetCore.OData, Version=7.4.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35()p4Equal($it, NULL) ? NULL : Convert($it.Id))), )]
 ---> MismatchedTreeNodeException(87!=3)
   --- End of inner exception stack trace ---
   at NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException()
   at NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate()
   at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Analyze(String collectionRole)
   at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(IDictionary`2 replacements, Boolean shallow, String collectionRole)
   at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
   at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
   at NHibernate.Engine.Query.QueryExpressionPlan.CreateTranslators(IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
   at NHibernate.Engine.Query.QueryExpressionPlan..ctor(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
   at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters)
   at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow)
   at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression)
   at NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, IQuery& query)
   at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
   at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)
   at Remotion.Linq.QueryableBase`1.System.Collections.IEnumerable.GetEnumerator()
   at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteResourceSet(IEnumerable enumerable, IEdmTypeReference resourceSetType, ODataWriter writer, ODataSerializerContext writeContext)
   at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)
   at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
   at Microsoft.AspNet.OData.Formatter.ODataOutputFormatterHelper.WriteToStream(Type type, Object value, IEdmModel model, ODataVersion version, Uri baseAddress, MediaTypeHeaderValue contentType, IWebApiUrlHelper internaUrlHelper, IWebApiRequestMessage internalRequest, IWebApiHeaders internalRequestHeaders, Func`2 getODataMessageWrapper, Func`2 getEdmTypeSerializer, Func`2 getODataPayloadSerializer, Func`1 getODataSerializerContext)
   at Microsoft.AspNet.OData.Formatter.ODataOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

The repository with the example: https://github.com/fairking/NhOdataTest

@fairking
Copy link
Author

Looks like the fix was here: #2079

@bahusoid
Copy link
Member

Exception looks the same as reported in your other PR #2334

And you've been already told that it will be fixed with #2079 when merged. So why another issue?

@fairking
Copy link
Author

Sorry, I thought it was merged or partially merged and was a fix of 5.3. Closing the issue.

@bahusoid
Copy link
Member

Duplicate of #2334

@bahusoid bahusoid marked this as a duplicate of #2334 Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants