MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

How to get the AspnetUsersInRoles to populate?  (Mono Support )

Viewed 8008 time(s), 3 post(s) 6/6/2013 9:13:46 PMby jharcariik
jharcariik

jharcariik

6/6/2013 9:13:46 PM
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
This content has not been rated yet. 
40 Reputation 4 Total posts
iruzak

iruzak

6/7/2013 6:02:47 AM
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
This content has not been rated yet. 
443 Reputation 50 Total posts
khorvat

khorvat

6/7/2013 9:53:28 AM
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
This content has not been rated yet. 
15993 Reputation 2214 Total posts