Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Get childrens from OrganizationUnit #6526


User avatar
0
pointlevel created

Hello!

How can i retrieve(Include) the Children as iCollection of OrganizationUnits when using this code from documentation?

            var user = await _userManager.GetUserByIdAsync(AbpSession.UserId.Value);
            var organizationUnits = await _userManager.GetOrganizationUnitsAsync(user);
            var organizationUnitIds = organizationUnits.Select(ou => ou.Id);

7 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team
    var organizationUnits = await _organizationUnitRepository
        .GetAllIncluding(ou => ou.Children)
        .Where(ou => organizationUnitIds.Contains(ou.Id))
        .ToListAsync();
    
  • User Avatar
    0
    pointlevel created

    so i need to make an additional query for that? First get the logged in user, then the OUs for that user, and then the OUs again with children?

  • User Avatar
    0
    aaron created
    Support Team

    Yes, if you want to use the code from the documentation. Otherwise, you can write your own join query.

  • User Avatar
    0
    pointlevel created

    Can you please show me how to write that query where i get the current user, users OU´s including its children?

    Thanks.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @pointlevel

    Have you managead to write that query ?

  • User Avatar
    0
    aaron created
    Support Team

    Copy the query in GetOrganizationUnitsAsync and make this change:

    - _organizationUnitRepository.GetAll()
    + _organizationUnitRepository.GetAllIncluding(ou => ou.Children)
    
  • User Avatar
    0
    pointlevel created

    Thank you aaron simplicity is the best!