count on related entities subtype

Posts   
 
    
wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 01-Sep-2008 13:25:19   

Hi Frans,

Probably related to this solved issue, but I didn't want to hijack the thread again: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=14152

This call fails with your latest attached debug versions:


[TestMethod()]
public void SelectCountOnAnySubtype()
        {
            var entities = _linqMetaData.Doelpakket
                .Where(x=>x.Elementen.Any(e=>e is ActiviteitEntity));

            Console.WriteLine(entities.Count());
        }

Output:


------ Test started: Assembly: CC.ECDGenie.Dal.UnitTests.dll ------

: Initial expression to process:
value(SD.LLBLGen.Pro.LinqSupportClasses.DataSource2`1[CC.ECDGenie.Dal.EntityClasses.DoelpakketEntity]).Where(x => x.Elementen.Any(e => (e Is ActiviteitEntity))).Count()
Method Enter: CreatePagingSelectDQ
Method Enter: CreateSelectDQ
Method Enter: CreateSelectDQ
Method Enter: CreateSubQuery
Method Enter: CreateSelectDQ
Method Enter: CreateSelectDQ
Generated Sql query: 
    Query: SELECT [LPA_L1].[versie_object_id] AS [VersieObjectId] FROM ( [dbo].[tb_ECDGenie_Element] [LPA_L1] (nolock) INNER JOIN [dbo].[tb_ECDGenie_DoelpakketElement] [LPA_D2] (nolock) ON  [LPA_L1].[id]=[LPA_D2].[element_id]) WHERE ( [LPLA_1].[id] = [LPA_D2].[doelpakket_id] AND ( ( [LPLA_2].[id] IS NOT NULL)))

Method Exit: CreateSelectDQ
Method Exit: CreateSubQuery
Generated Sql query: 
    Query: SELECT DISTINCT TOP(@top0) COUNT(*) AS [LPAV_] FROM [dbo].[tb_ECDGenie_Doelpakket] [LPLA_1] (nolock) WHERE ( ( (  EXISTS (SELECT [LPA_L1].[versie_object_id] AS [VersieObjectId] FROM ( [dbo].[tb_ECDGenie_Element] [LPA_L1] (nolock) INNER JOIN [dbo].[tb_ECDGenie_DoelpakketElement] [LPA_D2] (nolock) ON  [LPA_L1].[id]=[LPA_D2].[element_id]) WHERE ( [LPLA_1].[id] = [LPA_D2].[doelpakket_id] AND ( ( [LPLA_2].[id] IS NOT NULL)))))))
    Parameter: @top0 : Int64. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 1.

Method Exit: CreateSelectDQ
Method Exit: CreatePagingSelectDQ: no paging.
TestCase 'CC.ECDGenie.Dal.UnitTests.LlblgenTests.SelectCountOnAnySubtype'
failed: SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: The multi-part identifier "LPLA_2.id" could not be bound.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.
    SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: The multi-part identifier "LPLA_2.id" could not be bound.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception. ---> System.Data.SqlClient.SqlException: The multi-part identifier "LPLA_2.id" could not be bound.
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
    at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
    at System.Data.SqlClient.SqlDataReader.get_MetaData()
    at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
    at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
    at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
    at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior)
       --- End of inner exception stack trace ---
    at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior)
    at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchDataReader(IRetrievalQuery queryToExecute, CommandBehavior readerBehavior)
    D:\Projects\dotNet\Net3.5\CC.ECDGenie\MainLine\Dal\DatabaseSpecific\DataAccessAdapter.cs(292,0): at CC.ECDGenie.Dal.DatabaseSpecific.DataAccessAdapter.FetchDataReader(IRetrievalQuery queryToExecute, CommandBehavior readerBehavior)
    at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List`1 valueProjectors, IGeneralDataProjector projector, IRetrievalQuery queryToExecute, Dictionary`2 typeConvertersToRun)
    at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List`1 valueProjectors, IGeneralDataProjector projector, IEntityFields2 fields, IRelationPredicateBucket filter, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize)
    at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.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[TResult](Expression expression)
    at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
    D:\Projects\dotNet\Net3.5\CC.ECDGenie\MainLine\Dal\CC.ECDGenie.Dal.UnitTests\LlblgenTests.cs(152,0): at CC.ECDGenie.Dal.UnitTests.LlblgenTests.SelectCountOnAnySubtype()


Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 01-Sep-2008 14:55:22   

It's indeed the same issue, though as the dyn. list query takes a different code path at some point, it's query elements aren't updated properly apparently. I'll look into this. I though the fix posted last week was also taking this into account...

Frans Bouma | Lead developer LLBLGen Pro
wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 01-Sep-2008 15:02:29   

Otis wrote:

It's indeed the same issue, though as the dyn. list query takes a different code path at some point, it's query elements aren't updated properly apparently. I'll look into this. I though the fix posted last week was also taking this into account...

Do you have an award for people who submit the most bug reports? sunglasses

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 01-Sep-2008 15:56:10   

Not yet simple_smile But keep these bugreports coming. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 01-Sep-2008 18:47:14   

Fixed in the attached ORMSupportclasses.

there can be more bugs related to the multi-hop bug (like Any(a=>a.Foo.Bar.Bla....)) as we haven't done a full code review of the linq provider yet regarding this. This will be done tomorrow.

Frans Bouma | Lead developer LLBLGen Pro