Correct use of relations and prefetch path

Posts   
 
    
TogasPoon
User
Posts: 42
Joined: 09-Feb-2006
# Posted on: 24-Feb-2006 22:20:47   

I think this is correct but want to make sure I'm not doing more than I need to.

I'm displaying my results in a grid and use fields from a Parent, child and grandchild table.

TimeOff - Employee - Department

I want to sort first by Deparment and then by Employee so this is what I've come up with.


        'selfservicing

    'Where
    Dim pe As IPredicateExpression = New PredicateExpression
    pe.Add(PredicateFactory.CompareValue(TimeOffFieldIndex.StartDate, _
        ComparisonOperator.LessEqual, myDate.AddDays(1).AddMilliseconds(-1)))
    pe.AddWithAnd(PredicateFactory.CompareValue(TimeOffFieldIndex.EndDate, _
        ComparisonOperator.GreaterThan, myDate))

    'Sort
    Dim sorter As ISortExpression = New SortExpression
    sorter.Add(SortClauseFactory.Create(DepartmentFieldIndex.Department, SortOperator.Ascending))
    sorter.Add(SortClauseFactory.Create(EmployeeFieldIndex.FullName, SortOperator.Ascending))

    'join
    Dim relations As RelationCollection = New RelationCollection
    relations.Add(TimeOffEntity.Relations.EmployeeEntityUsingEmployeeId)
    relations.Add(EmployeeEntity.Relations. DepartmentEntityUsingDepartmentId)

    'Grab the related entities up front
    Dim prefetchPath As IPrefetchPath = New PrefetchPath(CInt(EntityType.TimeOffEntity))
    prefetchPath.Add(TimeOffEntity.PrefetchPathEmployee).SubPath.Add(EmployeeEntity.PrefetchPathDepartment)

    Dim TimeOffColl As New TimeOffCollection
    TimeOffColl.GetMulti(pe, 0, sorter, relations, prefetchPath)


Am I correct in assuming that I need the relationCollection in order to accomplish my sorting? And if I have a RelationCollection do I still need my prefetchpaths?

Thanks in advance.

Warren

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 25-Feb-2006 03:06:20   

I don't believe you would need the prefetch path unless you were going to access the data defined in the prefetch path. The relationCollection is needed for the sort, but the prefetchpath should not be.