Mono Support How to get the AspnetUsersInRoles to populate? 

Viewed 9276 time(s), 3 post(s), 6/6/2013 9:13:46 PM - by jharcariik
6/6/2013 9:13:46 PM
40 Reputation 4 Total posts

I am using the MonoX API, UserRepository class and the GetUser Method.  The AspnetUsersInRoles in always empty.
How do you get the AspnetUserInRoles to populate?

Below is my code:

private AspnetUsersEntity getMonoXAspnetUser(Guid userId)
{
     UserRepository mxUserRepository = UserRepository.GetInstance();
     AspnetUsersEntity aspnetUser = (AspnetUsersEntity)null;
     try
     {
         aspnetUser = mxUserRepository.GetUser(userId);
        // aspnetUser.AspnetUsersInRoles is empty 
        foreach (AspnetUsersInRolesEntity rItem in aspnetUser.AspnetUsersInRoles)  
        {
                    string wait = rItem.AspnetRoles.RoleName;
         }
     }
     finally
     {
         if (mxUserRepository != null)
         {
             mxUserRepository.Dispose();
             mxUserRepository = null;
         }
     }
     return aspnetUser;
}

These are the Roles that should be returned for the User I am testing with:
UserId                                                                RoleId                                                                RoleName
E1283E9D-2161-4799-AF69-A1C000CD0737 DD289A77-1525-456A-B98C-A1B7010CFB69 CLIENT
E1283E9D-2161-4799-AF69-A1C000CD0737 EBAF7B92-BB12-40C3-B3E4-FD40B9932E3E Users

Thanks.
Joe

1
6/7/2013 6:02:47 AM
443 Reputation 50 Total posts

Hi Joe,
that is correct. GetUser method fetches only entity from AspnetUsers table.
To achieve this functionality I suggest you read about LLBLGen Pro that MonoX uses here  about fetching data and prefetch.

Igor

2
6/7/2013 9:53:28 AM
15993 Reputation 2214 Total posts

To help you a bit with this ... you can use the following code, this should help you get started with LLBLGen and LINQ

AspnetUsersEntity user = null;
using (IDataAccessAdapter dataAdapter = GetAdapter())
{
    IPrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.AspnetUsersEntity);
    prefetch.Add(AspnetUsersEntity.PrefetchPathUserProfile);
    prefetch.Add(AspnetUsersEntity.PrefetchPathAspnetMembership);
    prefetch.Add(AspnetUsersEntity.PrefetchPathAspnetUsersInRoles);
 
    LinqMetaData metaData = new LinqMetaData(dataAdapter);
    user = (from usr in metaData.AspnetUsers
            where usr.UserId == id
            select usr).WithPath(prefetch).First();
}
return user;


Regards

3
This is a demo site for MonoX. Please visit Mono Software for more info.