Prefetch problem

Posts   
 
    
Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 02-Jun-2005 17:24:55   

Okay, Iv'e been battling this for a couple of hours and can not get it to work correctly. I have the following code:


Public Shared Function GetAllSubjectAreas() As EntityCollection
    Dim Sorter As ISortExpression = New SortExpression
    Sorter.Add(SortClauseFactory.Create(Elementary.GradeBook.LLBL.SubjectAreaFieldIndex.SortKey, SortOperator.Ascending))

    Dim Sorter2 As ISortExpression = New SortExpression
    Sorter2.Add(SortClauseFactory.Create(SubSkillFieldIndex.SortKey, SortOperator.Ascending))

    GetAllSubjectAreas = New EntityCollection(New SubjectAreaEntityFactory)

    Dim PrefetchPath As IPrefetchPath2 = New PrefetchPath2(CType(EntityType.SubjectAreaEntity, Integer))
    PrefetchPath.Add(SubjectAreaEntity.PrefetchPathSubSkill, Nothing, Nothing, Nothing, Sorter2)

    _Adapter.FetchEntityCollection(GetAllSubjectAreas, Nothing, Nothing, Sorter, PrefetchPath)

    Return GetAllSubjectAreas
End Function

It is suppose to fetch all SubjectArea and associated SubSkill records sorted by SortKey.

I get the following error when I run the code:

 See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32& uniqueMarker)
   at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)
   at MedfordSchoolDistrict.Elementary.GradeBook.LLBL.DatabaseSpecific.DataAccessAdapter.CreateSelectDQ(IEntityFields2 fieldsToFetch, IFieldPersistenceInfo[] persistenceInfoObjects, IPredicateExpression filter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) in C:\SISnet Project\ElementaryGradeBookLLBL\DatabaseSpecific\DataAccessAdapter.vb:line 521

This is the code in DataAccessAdapter that aborts

        Protected Overloads Overrides Function CreateSelectDQ(fieldsToFetch As IEntityFields2, persistenceInfoObjects As IFieldPersistenceInfo(), _
            filter As IPredicateExpression, maxNumberOfItemsToReturn As Long, sortClauses As ISortExpression, relationsToWalk As IRelationCollection, _
            allowDuplicates As Boolean, groupByClause As IGroupByCollection, pageNumber As Integer, pageSize As Integer) As IRetrievalQuery
            
            Return DynamicQueryEngine.CreateSelectDQ(fieldsToFetch.GetAsEntityFieldCoreArray(), _
                persistenceInfoObjects, MyBase.GetActiveConnection(), filter, maxNumberOfItemsToReturn, sortClauses, relationsToWalk, allowDuplicates, groupByClause, pageNumber, pageSize)
        End Function

The first Select on SubjectArea seems to go correctly. The second select is when it aborts. The predicate on the second select contains zero parameters, which does not seem right.

Any help would be greatly appriciated.

Fishy

btw, why is it when I paste my code in the forum it's left justified and when I paste your code it leaves the correct indented spacing?

JimFoye avatar
JimFoye
User
Posts: 656
Joined: 22-Jun-2004
# Posted on: 02-Jun-2005 17:28:03   

Fishy wrote:

btw, why is it when I paste my code in the forum it's left justified and when I paste your code it leaves the correct indented spacing?

Ha ha ha ha!!! It eats the spaces and leaves the tabs! Drives me nuts! smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 02-Jun-2005 17:36:59   

Tabs are converted to  , spaces are not.

The cause of the error is likely a difference between the dbgeneric project and the dbspecific project: a field in the dbgeneric entity isn't present in the persistence info. Could you check that for me, please?

Frans Bouma | Lead developer LLBLGen Pro
Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 02-Jun-2005 18:17:57   

flushed flushed flushed I would have staked your life (not mine, of course wink ) that I regenerated the code after I removed a field.

One day I'm going to have a real problem, then we'll see who has the last laugh smile .

Thanks...

Fishy