Restricting a Collection to one Relationship

Posts   
 
    
Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 13-Dec-2006 12:38:34   

I'm on v2.0.0.0 Final, SelfService, SQL Server 2005.

If a do a GetMulti(Nothing) on my EmployeeCollection, and give this to a Janus hierarchical grid, I get all relationships shown.

I want to restrict this to just one relationship. There is a (1:n) relationship between Employee and EmpAccount, with EmpAccount having a multi-field Pk, with the second field on EmpAccount called Pk2Employee:

Public Class Form1

    Dim clnEmps As New EmployeeCollection

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim rclAccounts As New RelationCollection()
        rclAccounts.Add(EmployeeEntity.Relations.EmpAccountEntityUsingPk2Employee)

        clnEmps.GetMulti(Nothing, rclAccounts)

        GridEX1.DataSource = clnEmps

        GridEX1.Hierarchical = True
        GridEX1.RetrieveStructure(True)

    End Sub

But I can still see all tables.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Dec-2006 13:27:21   

Do you mean you want to retrieve the Employee collection with the related EmpAccount Collection, without fetching other related entities.

Since you are using SelfServicing, these are being LazyLoaded. Only by using PrefetchPaths you can stop LazyLoading, but then PrefetchPaths will fetch the unwanted entities, so maybe you need to supply an impossible filter (filter that can't be true...eg(DepartementId == -1)) to the prefetchPaths, therefore nothing will be fetched back for the unwanted relations.

Steve Mann
User
Posts: 31
Joined: 22-Nov-2006
# Posted on: 13-Dec-2006 15:09:11   

Walaa wrote:

Do you mean you want to retrieve the Employee collection with the related EmpAccount Collection, without fetching other related entities.

Yes.

Since you are using SelfServicing, these are being LazyLoaded.

So I guess there's no performance hit.

Thanks for the info.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 14-Dec-2006 01:46:41   

With a prefetch path you have much better performance than with lazy loading if you are going to be using the related entities. The problem with selfservicing in your scenario is that whenever a property that maps to a related entity collection is read the related entity collection is fetched. I do not know exactly how related collections are used in the janus grids, but you may have to disable this automatic detection of related entities and take care of that behavior yourself in the grid using only the related entity that you desire the grid to show.