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