Autofetching related 1:1 entities

Posts   
 
    
MichielAlders avatar
Posts: 30
Joined: 01-Sep-2009
# Posted on: 17-Sep-2009 11:09:40   

Hi,

I have an entity (EC001) which has an 1:n relation with EC002 this entity has an 1:1 relation with EC003 and EC006.

EC002.Groep = EC003.Groep EC002.Item = EC006.Item

Now when I fetch 1 row from EC001 and fetch its related EntityCollection EC002 I would like to select the 1:1 objects also.


Dim EC001Obj as new Ec001Entity("Key1", "Key2")
Using adapter as new DataAccesAdapter
 adapter.FetchEntity(EC001Obj, Nothing)
 adapter.FetchEntityCollection(EC001Obj.Ec002, EC001Obj.GetRelationInfoEc002)
End Using

'That fills EC001Obj.Ec002 with the related EC002 objects but EC002(0).Ec003 and EC002(0).Ec006 are still 'Nothing'. Is there a way to fetch the 1:1 relational objects as well?

Thanks in advance

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 17-Sep-2009 11:50:07   

Please use prefetchPaths.

All of this can be fetched in one go:

Dim EC001Obj as new Ec001Entity("Key1", "Key2")
Dim prefetchPath As PrefetchPath2 = New PrefetchPath2(EntityType.Ec001Entity)
PrefetchPathElement2 ec002Path = prefetchPath.Add(Ec001Entity.PrefetchPathEc002...)

ec002Path.SubPath.Add(Ec002Entity.PrefetchPathEc003...)
ec002Path.SubPath.Add(Ec002Entity.PrefetchPathEc006...)

Using adapter as new DataAccesAdapter
adapter.FetchEntity(EC001Obj, prefetchPath )
End Using
MichielAlders avatar
Posts: 30
Joined: 01-Sep-2009
# Posted on: 17-Sep-2009 11:57:07   

Just came to the same conclusion:


        Using adapter As New DataAccessAdapter
            Dim path As New PrefetchPath2(CInt(EntityType.Ec001Entity))
            path.Add(Ec001Entity.PrefetchPathEc002)
            path(0).SubPath.Add(Ec002Entity.PrefetchPathEc003)
            path(0).SubPath.Add(Ec002Entity.PrefetchPathEc006)
            adapter.FetchEntity(obj, path)
        End Using