Skip to content

NH-3396 - Fetch requests do not work with collection projections #1298

Open
@nhibernate-bot

Description

@nhibernate-bot

Alexander Zaytsev created an issue — 13th February 2013, 2:03:54:

Follwing test will fail with exception:

var query = from o in db.Orders.FetchMany(x => x.OrderLines)
select new ExpandedWrapper<Order, ISet<OrderLine>>
{
ExpandedElement = o,
ProjectedProperty0 = o.OrderLines,
Description = "OrderLine",
ReferenceDescription = "OrderLine"
};

var result = query.ToList();
Assert.That(result.Count, Is.EqualTo(830));
Assert.That(NHibernateUtil.IsInitialized(result[0].ExpandedElement.OrderLines), Is.True);
Assert.That(NHibernateUtil.IsInitialized(result[0].ProjectedProperty0), Is.True);
Assert.That(result[0].ExpandedElement.OrderLines, Is.SameAs(result[0].ProjectedProperty0));

The exception:

System.ArgumentException : Expression of type 'System.Collections.IList' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[System.Object]'
at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ref ReadOnlyCollection`1 arguments)
at System.Linq.Expressions.Expression.Invoke(Expression expression, IEnumerable`1 arguments)
at NHibernate.Linq.ExpressionToHqlTranslationResults.MergeLambdas(IList`1 transformations) in ExpressionToHqlTranslationResults.cs: line 71
at NHibernate.Linq.ExpressionToHqlTranslationResults.MergeLambdasAndCompile(IList`1 itemTransformers) in ExpressionToHqlTranslationResults.cs: line 42
at NHibernate.Linq.ExpressionToHqlTranslationResults..ctor(HqlTreeNode statement, IList`1 itemTransformers, IList`1 listTransformers, IList`1 postExecuteTransformers, List`1 additionalCriteria) in ExpressionToHqlTranslationResults.cs: line 30
at NHibernate.Linq.IntermediateHqlTree.GetTranslation() in IntermediateHqlTree.cs: line 61
at NHibernate.Linq.Visitors.QueryModelVisitor.GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, Boolean root) in QueryModelVisitor.cs: line 69
at NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor sessionFactory, Boolean filter) in NhLinqExpression.cs: line 67
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in ASTQueryTranslatorFactory.cs: line 24
at NHibernate.Engine.Query.QueryExpressionPlan.CreateTranslators(IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in QueryExpressionPlan.cs: line 25
at NHibernate.Engine.Query.QueryExpressionPlan..ctor(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in QueryExpressionPlan.cs: line 12
at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters) in QueryPlanCache.cs: line 66
at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow) in AbstractSessionImpl.cs: line 412
at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression) in AbstractSessionImpl.cs: line 372
at NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, ref IQuery query, ref NhLinqExpression nhQuery) in DefaultQueryProvider.cs: line 70
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) in DefaultQueryProvider.cs: line 34
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) in DefaultQueryProvider.cs: line 41
at Remotion.Linq.QueryableBase`1.GetEnumerator() in c:\build\Remotion\working\Relinq\Core\QueryableBase.cs: line 132
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList(IEnumerable`1 source)
at NHibernate.Test.Linq.ProjectionsTests.ProjectKnownTypeWithCollectionShouldActuallyExpandOld() in ProjectionsTests.cs: line 352

Alexander Zaytsev added a comment — 13th February 2013, 2:18:18:

After resolving exception query becomes

select 
orderlines1_.OrderLineId as col_0_0_, 
orderlines1_.OrderLineId as col_1_0_, 
order0_.OrderId as col_2_0_, 
order0_.OrderId as col_3_0_, 
orderlines2_.OrderLineId as OrderLin1_31_2_, 
orderlines1_.OrderLineId as OrderLin1_31_0_, 
order0_.OrderId as OrderId30_1_, 
orderlines2_.OrderLineId as OrderLin1_31_2_, 
orderlines1_.OrderId as OrderId31_0_, 
orderlines1_.ProductId as ProductId31_0_, 
orderlines1_.UnitPrice as UnitPrice31_0_, 
orderlines1_.Quantity as Quantity31_0_, 
orderlines1_.Discount as Discount31_0_, 
order0_.CustomerId as CustomerId30_1_, 
order0_.EmployeeId as EmployeeId30_1_, 
order0_.OrderDate as OrderDate30_1_, 
order0_.RequiredDate as Required5_30_1_, 
order0_.ShippedDate as ShippedD6_30_1_, 
order0_.ShipVia as ShipVia30_1_, 
order0_.Freight as Freight30_1_, 
order0_.ShipName as ShipName30_1_, 
order0_.ShipAddress as ShipAdd10_30_1_, 
order0_.ShipCity as ShipCity30_1_, 
order0_.ShipRegion as ShipRegion30_1_, 
order0_.ShipPostalCode as ShipPos13_30_1_, 
order0_.ShipCountry as ShipCou14_30_1_, 
orderlines2_.OrderId as OrderId31_2_, 
orderlines2_.ProductId as ProductId31_2_, 
orderlines2_.UnitPrice as UnitPrice31_2_, 
orderlines2_.Quantity as Quantity31_2_, 
orderlines2_.Discount as Discount31_2_, 
orderlines2_.OrderId as OrderId0__, 
orderlines2_.OrderLineId as OrderLin1_0__ 
from 
Orders order0_ 
left outer join 
OrderLines orderlines1_ 
on order0_.OrderId=orderlines1_.OrderId 
left outer join 
OrderLines orderlines2_ 
on order0_.OrderId=orderlines2_.OrderId 

And test still does not pass.

This is logged as NH-3115

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions