How to display a related name

Posts   
 
    
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 18-Jul-2006 16:55:04   

Hi, I'm using V2, Adapter, Vb & WinForm. In part of my data model I have these 3 tables:

Employee: EmployeeID, Employeename EmployeeRole: EmployeeID, RoleID Role: RoleID, RoleName

With these relationships: Employee -< EmployeeRole >- Role

For a selected Employee I need to display RoleName from table Role in a dataGridView.

I can display RoleID from table EmployeeRole via:

    Function GetEmployeeRoles(ByVal EeID As Integer) As EntityCollection(Of EmployeeRoleEntity)
        Dim employeeRoles As New EntityCollection(Of EmployeeRoleEntity)(New EmployeeRoleEntityFactory())
        Dim prefetchPath As IPrefetchPath2 = New PrefetchPath2(CType(EntityType.EmployeeRoleEntity, Integer))
        prefetchPath.Add(EmployeeRoleEntity.PrefetchPathEmployee)
        Dim filter As IRelationPredicateBucket = New RelationPredicateBucket()
        filter.PredicateExpression.Add(EmployeeRoleFields.EmployeeId = EeID)
        Dim adapter As New DataAccessAdapter()
        Try
            adapter.FetchEntityCollection(employeeRoles, filter, prefetchPath)
            Return employeeRoles
        Finally
            adapter.Dispose()
        End Try
    End Function

.. but I don't know how to get hold of RoleName from table Role. There's a generated RoleRelations class available, but how do I use itconfused

Can anyone help ?

Thanks

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 19-Jul-2006 02:10:19   

It sounds like you have a many to many relationship. These are not automatically found for you by default. Read the section of the manual Designer - Adding custom relations - Adding m:n relations. See if this sheds any light on your scenario. Once you have this defined you can access the M:N relationships collection like this.

Dim employee As New EmployeeEntity(10)
Dim adapter As New DataAccessAdapter()
adapter.FetchEntityCollection(employee.Roles, employee.GetRelationInfoRoles())

More can be found on this in the manual here Generated code - Using the entity collection classes, Adapter - Using m:n relations