Hello all,
Sorry if I'm asking a question that has been answered already, but I have been struggling for the last couple days with a problem I don't know how to solve. I'm new to the concept of prefetch paths, so I read https://www.llblgen.com/Documentation/2.6/Using%20the%20generated%20code/SelfServicing/gencode_prefetchpaths.htm (I have several questions about this article, but that is for another day I suppose).
Currently, I'm not even sure what I'm getting back from the Db. It appears (from stepping through the program) that I'm getting back what is called an HoursOfService Violation (in this particular instance) is triggered when an employee works more than 6 days consecutively. When the report is run (to show violations for a month) it shows (for one violation):
Date / time shift started Shift Type
12/11/18 3 A Type2
12/12/18 4 A Type1
12/13/18 5 A Type2
12/14/18 6 A Type2
12/15/18 1 P Type1
12/15/18 1 P Type1
12/15/18 1 P Type1
12/16/18 12 P Type1
12/16/18 12 P Type1
12/17/18 3 A Type2
I would like it to show JUST 7 days (the six days prior to the violation and the day of the violation). I honestly feel like I'm shooting in the dark as senior developers here are confused about prefetch paths as well.
Here is some of the code I "think?" applies to the fetching of the Violation... but I'm shooting in the dark. Also, holidays are coming up and I'm also working on a couple other tasks, so I may be slow in responding at times. Thank you for your help and patience.
Public Function GetHOSViols(ByVal startDate As DateTime, ByVal endDate As DateTime) As EntityCollection(Of HosTour_HosViolationTypeEntity)
Dim hosViolsCollection As New EntityCollection(Of HosTour_HosViolationTypeEntity)
Dim adapter As DataAccessAdapter = Client.Remoting.BaseService.GetAdapter()
' Create a filter by date.
' ToDo: Fix Predicate Expression to filter based on a child relationship
Dim filter As RelationPredicateBucket = New RelationPredicateBucket()
filter.PredicateExpression.Add(New FieldBetweenPredicate(HosTour_HosViolationTypeFields.DateOfViolation, Nothing, startDate, endDate))
' Create all prefetch path scenarios
' Adds specified element to the path (EntityType.HosTour_HosViolationTypeEntity, Integer)
Dim prefetch As New PrefetchPath2(CType(EntityType.HosTour_HosViolationTypeEntity, Integer))
With prefetch.Add(HosTour_HosViolationTypeEntity.PrefetchPathHdt).SubPath
With .Add(HdtEntity.PrefetchPathHa).SubPath
.Add(HaEntity.PrefetchPathEmpPos)
.Add(HaEntity.PrefetchPathHosCd)
.Add(HaEntity.PrefetchPathEmpTyp)
End With
.Add(HdtEntity.PrefetchPathHosComSvc)
.Add(HdtEntity.PrefetchPathHosDeadheading)
.Add(HdtEntity.PrefetchPathEmp)
.Add(HdtEntity.PrefetchPathAmendRec)
End With
prefetch.Add(HosTour_HosViolationTypeEntity.PrefetchPathHosViolationType)
adapter.FetchEntityCollection(hosViolsCollection, filter, prefetch)
hosViolsCollection.Sort(HosTour_HosViolationTypeFieldIndex.DateOfViolation, ComponentModel.ListSortDirection.Ascending)
Return hosViolsCollection
End Function