Prefetch Filter on Related Table

Posts   
 
    
Bruce
User
Posts: 61
Joined: 18-May-2006
# Posted on: 23-Apr-2007 12:43:56   

Using SelfServicing, Net 1.1, LlblGenPro 2.0.

I have three related tables - Site, SiteInsp, Action.

The table SiteInsp contains details of scheduled Site Inspections. Table Actions contains details of Actions required as a result of each Inpection.

Relationships are: Site(1) to SiteInspection(m) on SiteId SiteInsp(1) to Action(m) on SiteInspId.

I want to set up a Prefetch so that all Stes are fetched. Related Inspections are only fetched if they are not done (SiteInsp.DoneDate is Null) or if the have outstanding Actions (Action.Closed is Null). SiteInsp.DoneDate and Action.Closed are smalldatetime fields.

My code is:

            Dim prefetchPath As IPrefetchPath = New prefetchPath(CType(EntityType.SiteEntity, Integer))

            Dim siteInspFilter As IPredicateExpression = New PredicateExpression
            siteInspFilter.Add(New FieldCompareNullPredicate(SiteInspFields.DoneDate))

            siteInspFilter.AddWithOr(New FieldCompareNullPredicate(ActionFields.Closed))

            Dim relSiteInsp As IRelationCollection = New RelationCollection
            relSiteInsp.Add(SiteInspEntity.Relations.ActionEntityUsingSiteInspId)

            prefetchPath.Add(SiteEntity.PrefetchPathSiteInsp, 0, relSiteInsp, siteInspFilter)
            Me.SiteColl.GetMulti(Nothing, prefetchPath)

This fails on the prefetchPath.Add line with the message "Specified cast is not valid". What am I doing wrong please?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39922
Joined: 17-Aug-2003
# Posted on: 23-Apr-2007 13:43:12   

Please post the stacktrace.

Frans Bouma | Lead developer LLBLGen Pro
Bruce
User
Posts: 61
Joined: 18-May-2006
# Posted on: 23-Apr-2007 19:46:20   

Well, I've spent all afternoon trying to get a Stack Trace on this one.

All I can get is: "SiteInspection.Win.fmSites.fmSites (C:\Documents and Settings\Bruce\My Documents\Visual Studio Projects\DD\SiteInspection\SiteInspection.Win\fmSites.vb, Line 554, Col 13,il OFFSET 126, native offset 440) The program '[220] SiteInspection.Win.exe' has exited with code 0 (0x0)."

I've stepped through the programme and put try/catch statements in various places in the LLBLGen generated code but none of these enter the catch area. It comes out of the generated code to the line prefetchPath.Add(SiteEntity.PrefetchPathSiteInsp, 0, relSiteInsp, siteInspFilter) then jumps to the catch statement. I used the following code to capture and examine the Stack Trace for the exception:

    Public Sub DisplayExceptionInfo(ByVal e As Exception, ByVal fm As Form)
        Debug.WriteLine(e.Message)
        Dim res As String = ""
        Dim st As New StackTrace(e, True)
        For i As Integer = 0 To st.FrameCount - 1
            Dim sf As StackFrame = st.GetFrame(i)
            Dim mi As MemberInfo = sf.GetMethod
            res &= mi.DeclaringType.FullName & "." & fm.Name & " ("
            If sf.GetFileName <> "" Then
                res &= String.Format("{0}, Line {1}, Col {2},", _
                sf.GetFileName, sf.GetFileLineNumber, sf.GetFileColumnNumber)
            End If
            If sf.GetILOffset <> StackFrame.OFFSET_UNKNOWN Then
                res &= String.Format("il OFFSET {0},", sf.GetILOffset)
            End If
            res &= " native offset " & sf.GetNativeOffset & ")"
            Debug.WriteLine(res)
        Next
    End Sub

Both the Windows project and the data (LLLBGen) project are in debug build mode.

I don't know what else I can do.

Bruce
User
Posts: 61
Joined: 18-May-2006
# Posted on: 24-Apr-2007 08:42:29   

Last night I re-built this part of my solution in .net 2 where intellisense showed that I'd got the prefetch arguments for the Filter and the Relationship in the wrong place. Should be

prefetchPath.Add(SiteEntity.PrefetchPathSiteInsp, 0, siteInspFilter, relSiteInsp)

For some reason intellisense did not highlight this error in .net 1.1 (BUG ?).

Next problem is that the filter does not achieve what I wanted. Further investigation today, but this will be a new thread if I cannot solve it.

Bruce
User
Posts: 61
Joined: 18-May-2006
# Posted on: 24-Apr-2007 09:02:57   

Had to add a JoinHint then it worked as required thus:

relSiteInsp.Add(SiteInspEntity.Relations.ActionEntityUsingSiteInspId,JoinHint.Left)

Hooray - on to the next!