PrefetchPath Error with Nulls

Posts   
 
    
Bruce
User
Posts: 61
Joined: 18-May-2006
# Posted on: 23-Apr-2007 10:23:27   

I am using LlBgenPro V2 with .Net 1.1.

I have a situation with a database containing tables Contract and Site. These have a 1:m relationship on the field ContractId. Contract is the 1 and Site is the m. However not all Sites have a Contract so ContractId is nullable in the Site table. ContractId is the PK of table Contract.

I have a grid showing Site details with a column showing ContractName (from the Contract table). This works fine but causes a query to happen for each Contract so I want to use a prefetch path.

My code is

            Dim prefetchPath As IPrefetchPath = New prefetchPath(CType(EntityType.SiteEntity, Integer))
            prefetchPath.Add(SiteEntity.PrefetchPathContract)
            Me.SiteColl.GetMulti(Nothing, prefetchPath)

This causes an error "Object reference not set to an instance of an object".

I've tried various modifications such as adding in but still get the same error:

            Dim relations As IRelationCollection = New RelationCollection
            relations.Add(SiteEntity.Relations.ContractEntityUsingContrId, JoinHint.Left)
            prefetchPath.Item(0).Relation.HintForJoins = JoinHint.Left

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Apr-2007 10:50:31   

Which runtimeLibrary version are you using? Try to use the latest please, and see if the problem still exists. _The runtime library version is obtainable by rightclicking the SD.LLBLGen.Pro.ORMSupportClasses.NETxy.dll in windows explorer and then by selecting properties and the version tab. The version is then enlisted at the top as the fileversion. It has the typical format as 2.0.0.YYMMDD, or starting in 2007, the format 2.0.YY.MMDD _

Bruce
User
Posts: 61
Joined: 18-May-2006
# Posted on: 23-Apr-2007 11:47:06   

I installed the latest version so SD.LLBLGen.Pro.ORMSupportClasses.NET11.dll version is now 2.0.07.0416 and the SD.LLBLGen.Pro.DQE.SqlServer.NET11.dll version is 2.0.07.0129.

I re-built the solution and checked that these dll versions are in the bin folders of both the data and the windows projects.

Still the same problem.

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

Please post the stacktrace. An exception without a stacktrace is meaningless.

Frans Bouma | Lead developer LLBLGen Pro
Bruce
User
Posts: 61
Joined: 18-May-2006
# Posted on: 24-Apr-2007 09:57:23   

Again no stack trace in Net 1.1 so I re-created it in Net 2.0 which immediately highlighted the problem.

I had added this to the SiteEntity class:

       Public ReadOnly Property ContrName() As String
            Get
                     Return Me.Contract.ContrName
            End Get
        End Property

Had to replace it with this to cure the problem

       Public ReadOnly Property ContrName() As String
            Get
                If Me.Contract Is Nothing Then
                    Return ""
                Else
                    Return Me.Contract.ContrName
                End If
            End Get
        End Property

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Apr-2007 10:11:39   

Glad you solved it