Grouping / Subquery by Substring results in Exception

Posts   
 
    
Whitey
User
Posts: 2
Joined: 09-Feb-2009
# Posted on: 09-Feb-2009 12:14:25   

Hello,

I am trying to group a set of records by first letter and use that to subquery as to have an instant hierarchy. I'm using the following code:

var entities = (from dossier in linqMetaData.Dossier
                group dossier by dossier.Title.Substring(0, 1) into dossiers
                select new
                {
                    dossiers.Key,
                    Dossiers = (
                       from d in linqMetaData.Dossier
                       where d.Title.Substring(0,1) == dossiers.Key
                       select d)
                });

foreach(var entity in entities)
{
    // bla
}

This results in the following exception: Results in the following exception:

ORMQueryConstructionException:

A nested query in the projection has no correlation filter to tie its set to the containing parent row. Please add a correlation filter to the where clause of this query to tie the nested query to the parent.

"   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.QueryExpression.FindCorrelationFilterPredicates(IElementCreatorCore generatedCodeElementCreator)
   at SD.LLBLGen.Pro.LinqSupportClasses.ValueListProjectionDefinition.AddNestedQueryToProjection(QueryExpression nestedQuery, String elementName, Type elementType, Boolean addConstantHandlerToProjection, ITemplateGroupSpecificCreator frameworkElementCreator, IElementCreatorCore generatedCodeElementCreator)
   at SD.LLBLGen.Pro.LinqSupportClasses.ValueListProjectionDefinition.AddProjectionListToProjection(ProjectionListExpression toAdd, ITemplateGroupSpecificCreator frameworkElementCreator, IElementCreatorCore generatedCodeElementCreator)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleProjectionExpression(ProjectionExpression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.HandleExpressionTree(Expression expression)
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression)
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression)
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.Execute()
   at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
    .
    .

RuntimeBuid Version: "11142008" RuntimeVersion: "2.6.0.0"

To my opinion there IS a where clause. What am I missing? wink

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 09-Feb-2009 13:16:21   

Try with the latest llblgenprolinq library posted by Frans: http://www.llblgen.com/tinyforum/Attachments.aspx?SourceType=1&MessageID=84858

Whitey
User
Posts: 2
Joined: 09-Feb-2009
# Posted on: 09-Feb-2009 13:51:31   

This newer version resulted in the same exception disappointed

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 09-Feb-2009 16:46:02   

I think it's the substring, which might be the problem, as the current version only supports field==field predicates.

The main reason for this is that the predicate is broken up, the first part is in the parent set and the second part is in the nested query and both have to be the same when the sets are merged, however as you execute a function this doesn't have to be the case in memory. (in your situation it is the same, in others it's not).

So as it can't find a field==field predicate, it gives up.

Frans Bouma | Lead developer LLBLGen Pro