Weird Error in Prefetch

Posts   
 
    
nirataro
User
Posts: 5
Joined: 14-Jun-2006
# Posted on: 17-Apr-2010 18:56:01   

I encountered a weird error in trying to use WithPath in my LINQ statement

var q = from x in meta.OrderAssignment.WithPath( p => p.Prefetch( pp => pp.Employee)) where x.DateCreated < assignedOn select x.Order;

I am not sure what cause it because it looks like a garden variety prefetch statement. Below is the dump file.

TestCase 'Speed.Main.Tests.Queries.Common.Tests.OrderAssignmentQueryTests.GetAllOrdersAssignedToTrucksToday' failed: SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException : An exception was caught during the execution of a retrieval query: The multi-part identifier "LPLA_1.DateCreated" could not be bound. The multi-part identifier "LPLA_1.OrderID" 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_1.DateCreated" could not be bound. The multi-part identifier "LPLA_1.OrderID" could not be bound. at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchDataReader(IRetrievalQuery queryToExecute, CommandBehavior readerBehavior) C:\Repository\Speed\trunk\Web\Speed.Data\DatabaseSpecific\DataAccessAdapter.cs(292,0): at Speed.Data.DatabaseSpecific.DataAccessAdapter.FetchDataReader(IRetrievalQuery queryToExecute, CommandBehavior readerBehavior) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List1 valueProjectors, IGeneralDataProjector projector, IRetrievalQuery queryToExecute, Dictionary2 typeConvertersToRun) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List1 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.ExecuteHierarchicalValueListProjection(QueryExpression toExecute, IRelationPredicateBucket additionalFilter, ITemplateGroupSpecificCreator frameworkElementCreator) 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(Expression expression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) Queries\Common\OrderAssignmentQuery.cs(71,0): at Speed.Main.Queries.Common.OrderAssignmentQuery.<>c__DisplayClassd.<GetOrdersAssignedToTruckToday>b__b(LinqMetaData meta) ORM\Query.cs(26,0): at Speed.Data.ORM.Query.Get[T](Func2 query) Queries\Common\OrderAssignmentQuery.cs(60,0): at Speed.Main.Queries.Common.OrderAssignmentQuery.GetOrdersAssignedToTruckToday(Int32 truckId, OrderStatus status) Queries\Common\Tests\OrderAssignmentQueryTests.cs(19,0): at Speed.Main.Tests.Queries.Common.Tests.OrderAssignmentQueryTests.GetAllOrdersAssignedToTrucksToday() --SqlException 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() 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)

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Apr-2010 20:02:41   

Some observations:

  1. Your query return x.Order with I assume is an OrderAssignment's field or the navigator in such m:n relation. The thing is that you can only use PrefetchPaths with entity resulset.

  2. You are specifying WithPath inside the query and not at the end. I know that works for PathEdges, not sure if it work for lambda expressions. The recommended way is:

var q = (from x in meta.OrderAssignment
                            where x.DateCreated < assignedOn
                            select x)
                 .WithPath( p => p.Prefetch( pp => pp.Employee));

Maybe it's not clear what set of entities you want to fetch, you could provide an approximate and equivalent sql snippet you want to reproduce.

If you need further help please provide your LLBLGen runtime library version and the generated sql.

David Elizondo | LLBLGen Support Team