Skip to content

InvalidCastException for Linq query with subquery #2515

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

Closed
cremor opened this issue Sep 3, 2020 · 0 comments
Closed

InvalidCastException for Linq query with subquery #2515

cremor opened this issue Sep 3, 2020 · 0 comments

Comments

@cremor
Copy link
Contributor

cremor commented Sep 3, 2020

I've just updated from NHibernate 5.2.7 to 5.3.2 and now one of my queries is failing.

I've simplified the failing query to this:

Customer customerParameter = ...

var customersSubquery = Query<SomeEntity>()
   .Select(x => x.Customer)
   .Where(x => x != customerParameter);

var result = Query<SomeOtherEntity>()
   .Where(x => customersSubquery.Contains(x.Customer))
   .ToArray();

This is the exception I get:

System.InvalidCastException: Unable to cast object of type 'NHibernate.Persister.Entity.SingleTableEntityPersister' to type 'NHibernate.Persister.Collection.IQueryableCollection'.

Full stack:

NHibernate.dll!NHibernate.Linq.Visitors.ParameterTypeLocator.SetParameterTypes(System.Collections.Generic.IDictionary<System.Linq.Expressions.ConstantExpression, NHibernate.Param.NamedParameter> parameters, Remotion.Linq.QueryModel queryModel, System.Type targetType, NHibernate.Engine.ISessionFactoryImplementor sessionFactory, bool removeMappedAsCalls) Line 116
NHibernate.dll!NHibernate.Linq.NhLinqExpression.Translate(NHibernate.Engine.ISessionFactoryImplementor sessionFactory, bool filter) Line 94
NHibernate.dll!NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(NHibernate.IQueryExpression queryExpression, string collectionRole, bool shallow, System.Collections.Generic.IDictionary<string, NHibernate.IFilter> filters, NHibernate.Engine.ISessionFactoryImplementor factory) Line 20
NHibernate.dll!NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(NHibernate.IQueryExpression queryExpression, bool shallow, System.Collections.Generic.IDictionary<string, NHibernate.IFilter> enabledFilters) Line 63
NHibernate.dll!NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(NHibernate.IQueryExpression queryExpression, bool shallow) Line 584
NHibernate.dll!NHibernate.Impl.AbstractSessionImpl.CreateQuery(NHibernate.IQueryExpression queryExpression) Line 552
NHibernate.dll!NHibernate.Linq.DefaultQueryProvider.PrepareQuery(System.Linq.Expressions.Expression expression, out NHibernate.IQuery query) Line 208
NHibernate.dll!NHibernate.Linq.DefaultQueryProvider.ExecuteList<MyEntityType>(System.Linq.Expressions.Expression expression) Line 107
NHibernate.dll!NHibernate.Linq.NhQueryable<MyEntityType>.System.Collections.Generic.IEnumerable<MyEntityType>.GetEnumerator() Line 65
System.Core.dll!System.Linq.Buffer<MyEntityType>.Buffer(System.Collections.Generic.IEnumerable<MyEntityType> source)
System.Core.dll!System.Linq.Enumerable.ToArray<MyEntityType>(System.Collections.Generic.IEnumerable<MyEntityType> source)
@fredericDelaporte fredericDelaporte added this to the 5.3.3 milestone Sep 6, 2020
@fredericDelaporte fredericDelaporte changed the title [5.3.x regression] InvalidCastException in ParameterTypeLocator.SetParameterTypes for Linq query with subquery InvalidCastException for Linq query with subquery Sep 6, 2020
@hazzik hazzik added the r: Fixed label Sep 9, 2020
@hazzik hazzik closed this as completed Sep 9, 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

3 participants