Hi guys,
I have a strange error when using prefetch path with this code:
using (var adapter = ...)
{
var bucket = new RelationPredicateBucket(GroupFields.Deleted == 0);
var collection = new EntityCollection<GroupEntity>();
var path = GroupEntity.PrefetchPathMembers;
adapter.FetchEntityCollection(collection, bucket, new PrefetchPath2(EntityType.GroupEntity) { path });
Description about the model:
I have these entities:
1. Enity Subject with these fields:
ID int PK
Deleted bit
Name nvarchar
MemberOf (M:N) with Groups
-
Enity Group(inherited from Subject FK by ID field) with these fields:
ID int PK
Members (M:N) with Subjects
-
Entity GroupMembership
ID int PK
GroupID FK to Group
SubjectID FK to Subjcet
The error is:
Tests.FetchGroups : Failed SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException : An exception was caught during the execution of a retrieval query: The multi-part identifier "net.sysSubject.Deleted" 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 "net.sysSubject.Deleted" could not be bound.
at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Query\RetrievalQuery.cs: line 136
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteMultiRowDataTableRetrievalQuery(IRetrievalQuery queryToExecute, DbDataAdapter dataAdapterToUse, DataTable tableToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo) in DataAccessAdapterBase.cs: line 790
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedList(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) in DataAccessAdapterBase.cs: line 3067
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.MergeManyToMany(IPrefetchPathElement2 currentElement, IRelationPredicateBucket elementFilter, Int64 maxNumberOfItemsToReturn, IEntityCollection2 rootEntities) in DataAccessAdapterBase.cs: line 5293
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Boolean forceParameterizedPPath) in DataAccessAdapterBase.cs: line 5223
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in DataAccessAdapterBase.cs: line 2467
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, IPrefetchPath2 prefetchPath) in DataAccessAdapterBase.cs: line 2305
at Intelex.Business.Tests.PerformanceTests.FetchLocationRolesFramework() in PerformanceTests.cs: line 64
--SqlException
at System.Data.SqlClient.SqlConnection.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 SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Query\RetrievalQuery.cs: line 112
If there is one or two records for Groups it works fine, if there is a lot of records it tries to use a sub query to filter m:n relation and the whole query fails.
I'm not completely sure what is going on and what is the problem, as for me the code looks ok.
Can you please help me with sorting it out?
LLBlgen version: 3.1.11.0907
The query which fails:
exec sp_executesql N'
SELECT DISTINCT [LPA_G2].[ID] AS [Id0], [LPA_L4].[ID] AS [Id1]
FROM ((( [net].[sysSubject] [LPA_G1]
INNER JOIN [net].[sysGroup] [LPA_G2] ON [LPA_G1].[ID]=[LPA_G2].[ID])
INNER JOIN [net].[sysGroupMembership] [LPA_G3] ON [LPA_G2].[ID]=[LPA_G3].[GroupID])
INNER JOIN [net].[sysSubject] [LPA_L4] ON [LPA_L4].[ID]=[LPA_G3].[SubjectID])
WHERE ( ( [LPA_G3].[GroupID] IN (
SELECT [net].[sysGroup].[ID] AS [Id]
FROM ( [net].[sysSubject] [LPA_L4]
INNER JOIN [net].[sysGroup] ON [LPA_L4].[ID]=[net].[sysGroup].[ID])
WHERE ( ( ( [net].[sysSubject].[Deleted] = @p1) AND ( [net].[sysGroup].[ID] IS NOT NULL))))))',N'@p1 bit',@p1=0
go
Thanks,
Anton