Linq Group By throwing Invalid Column Name

Posts   
 
    
billa1972
User
Posts: 9
Joined: 05-Feb-2004
# Posted on: 13-Aug-2008 19:55:13   

Hi,

i have the following linq query:

        var siByEndUser = from sri in context.ServiceRequestItem
                          where sri.TaskId == 242
                          group sri by sri.RequesteePersonId into g
                          select g;

which is throwing an invalid column name "RequesteePersonId" because the column name is actually named Requestee_Person_Id ([LPLA_4].[RequesteePersonId] = @RequesteePersonId2)

here is the generated query...Note the select column and alais is correct, but the where clause on the column is using the alias column name instead of the actual column name. This looks like a bug.

I have downloaded the latest templates and runtime libraries posted on 8/4/2008.

---------- Query Executed -----------------

Query: SELECT [LPLA_4].[Service_Request_Item_ID] AS [ServiceRequestItemId], [LPLA_4].[Service_Request_ID] AS [ServiceRequestId], [LPLA_4].[Service_Request_Item_Num] AS [ServiceRequestItemNum], [LPLA_4].[Provisioning_Group_ID] AS [ProvisioningGroupId], [LPLA_4].[Requestee_Person_ID] AS [RequesteePersonId], [LPLA_4].[Resource_ID] AS [ResourceId], [LPLA_4].[Action_ID] AS [ActionId], [LPLA_4].[Task_ID] AS [TaskId], [LPLA_4].[When_Received_UTC_DateTime] AS [WhenReceivedUtcDateTime] FROM [SI_ART_Proto].[dbo].[Service_Request_Item] [LPLA_4]  WHERE ( ( ( ( [LPLA_4].[Task_ID] = @TaskId1)) AND ( [LPLA_4].[RequesteePersonId] = @RequesteePersonId2)))
Parameter: @TaskId1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 242.
Parameter: @RequesteePersonId2 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 159579.

--------------- Stack Trace -------------------- at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, ITransaction containingTransaction, IEntityCollection collectionToFill, Boolean allowDuplicates, IEntityFields fieldsUsedForQuery, IFieldPersistenceInfo[] fieldPersistenceInfos) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAction(ITransaction containingTransaction, IEntityCollection collectionToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, IPrefetchPath prefetchPathToUse, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetMulti(ITransaction containingTransaction, IEntityCollection collectionToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IEntityFactory entityFactoryToUse, IPredicate selectFilter, IRelationCollection relations, IPrefetchPath prefetchPathToUse, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase1.GetMulti(IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, IPrefetchPath prefetchPathToUse, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider.ExecuteEntityProjection(QueryExpression toExecute) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider.ExecuteHierarchicalValueListProjection(QueryExpression toExecute, IPredicateExpression additionalFilter, ITemplateGroupSpecificCreator frameworkElementCreator) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider.ExecuteValueListProjection(QueryExpression toExecute) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) 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.LLBLGenProQuery1.Execute() at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at TemplateTest.Form1.Test() in c:\kt\TemplateTest\TemplateTest\Form1.cs:line 33

Thanks for any help!

Bill

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 13-Aug-2008 20:37:40   

Ah, I see, I think this is a small bug related to field re-use inside the query where it should have made a clone. The query you're seeing is a nested query, executed after the groupby has been ran. If you don't need a hierarchy returned, consider a temporary workaround where you fetch the gruoped data into a new anonymous type for the time being till we've fixed this bug.

Frans Bouma | Lead developer LLBLGen Pro
billa1972
User
Posts: 9
Joined: 05-Feb-2004
# Posted on: 13-Aug-2008 20:47:20   

Hi,

yep, no prob....got the temporary fix in place.

Thanks for a wicked cool product!

bill

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 14-Aug-2008 10:41:22   

billa1972 wrote:

Hi,

yep, no prob....got the temporary fix in place.

Thanks for a wicked cool product!

bill

simple_smile

I reproduced it. Our tests succeeded (we did have a similar query) because we grouped on a field which had the same name as the mapped tablefield. Grouping on a renamed field made the query crash. Looking into it to fix it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 14-Aug-2008 11:58:37   

Fixed (and fixed another related small bug as well). See attached dll simple_smile

Frans Bouma | Lead developer LLBLGen Pro
billa1972
User
Posts: 9
Joined: 05-Feb-2004
# Posted on: 14-Aug-2008 18:00:34   

You are awesome, works like a champ!

thanks, bill