A filter for my prefetchPath

Posts   
 
    
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 07-Jan-2008 18:42:29   

Hi, (Using Adapter V2.5/VB/SQL Server 2005/WinForm)

I maintain user roles in a grid via 2 related tables (UserRole & Role):

UserRole UserID RoleID (FK related to Role table)

Role RoleID RoleName RoleDescription

The grid is sourced from the following, but my prefetchPath filter isn't working.

    Function GetRoleNames(ByVal UserID As String) As EntityCollection
        Dim roleNames As New EntityCollection(New RoleEntityFactory())
        Dim filter As IPredicateExpression = New PredicateExpression
        filter.Add(UserRoleFields.UserID = UserID)
        Dim prefetchPath As IPrefetchPath2 = New PrefetchPath2(CInt(EntityType.RoleEntity))
        prefetchPath.Add(RoleEntity.PrefetchPathUserRole, Nothing, filter)
        Dim adapter As New DataAccessAdapter()
        Try
            adapter.FetchEntityCollection(roleNames, Nothing)
            Return roleNames
        <snip>

What am I missing? Thanks

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 07-Jan-2008 19:15:04   

my vb is rusting, but here it is in c#. you don't need prefetch paths for this.

public EntityCollection<RoleEntity> GetRoleNames(string userId)
{
     EntityCollection<RoleEntity> listOfRoles = new EntityCollection<RoleEntity>();

     IRelationPredicateBucket bucket = new RelationPredicateBucket();
     bucket.Relations.Add(RoleEntity.Relations.UserRoleOnRoleId);
     bucket.PredicateExpression.Add(UserRoleFields.UserId == userId);

     adapter.FetchEntityCollection(listOfRoles, bucket);

     return listOfRoles;
}
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 07-Jan-2008 20:22:13   

Jason,

That's terrific sunglasses I just needed to change '.UserRoleOnRoleId' to '.UserRoleEntityUsingRoleID' and it gave me what I needed + some info on relations.

For the record (and for future use), how does one specify a filter within a prefetchPath?

Thanks again wink

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 07-Jan-2008 20:36:58   

you can either do it through the ctor or using the SubPath.Filter property