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