Prefetch Path and m:n problem

Posts   
 
    
peschkaj
User
Posts: 30
Joined: 21-Sep-2006
# Posted on: 02-Oct-2007 19:43:57   

I'm trying to pull back a User object with some of the related entities.

A user belongs to potentially multiple roles through the UsersInRoles table. This table has the following fields: UserID, OrganizationID, RoleID.

I'm having problems writing the prefetch to pull back a user and all of their organizations and roles. This is what I have right now, but it is not working.

UserEntity _user = new UserEntity(userID);

IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.UserEntity);
prefetchPath.Add(UserEntity.PrefetchPathUserInRoleCollection).SubPath.Add(UserInRoleEntity.PrefetchPathOrganization ).SubPath.Add(OrganizationEntity.PrefetchPathOrganizationType);
prefetchPath.Add(UserEntity.PrefetchPathUserInRoleCollection).SubPath.Add(UserInRoleEntity.PrefetchPathRole);

DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchEntity(_user, prefetchPath);
return _user;

We're getting an exception saying that the PrefetchPathUserInRoleCollection is already in use, but I'm not sure how else to add this.

Thanks,

Jeremiah

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Oct-2007 12:05:18   

Try the following:

UserEntity _user = new UserEntity(userID);

IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.UserEntity);

PrefetchPathElement2 userInRolePrefetchPath = UserEntity.PrefetchPathUserInRoleCollection;

userInRolePrefetchPath.SubPath.Add(UserInRoleEntity.PrefetchPathOrganization).SubPath.Add(OrganizationEntity.PrefetchPathOrganizationType);

userInRolePrefetchPath.SubPath.Add(UserInRoleEntity.PrefetchPathRole);

prefetchPath.Add(userInRolePrefetchPath);

DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchEntity(_user, prefetchPath);
return _user;