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

Query users from other application service #8650


User avatar
0
rvanwoezik created

ASP.NET Core - Angular 8.21 Hi, i have something weird. I have an EmployeeAppService which query users, it worked in v8.0

public async Task<PagedResultDto<EmployeeListDto>> GetEmployees(GetEmployeesInput input)
        {
            var query = _userRepository.GetAll()
                .Include(u => u.TherapistWorkHours)
                .Include(u => u.HomeAddress)
                .Include(u => u.PostalAddress)
                .WhereIf(
                    !input.Filter.IsNullOrWhiteSpace(),
                    u =>
                        u.Name.Contains(input.Filter) ||
                        u.Surname.Contains(input.Filter) ||
                        u.UserName.Contains(input.Filter) ||
                        u.EmailAddress.Contains(input.Filter)
                );

            var users = query
                .Where(u => u.UserName != "admin")
                .OrderByDescending(u => u.HireDate).AsQueryable();

            var employeesCount = await query.CountAsync();

            var employees = users
                .OrderBy(input.Sorting)
                .PageBy(input)
                .ToListAsync();

            var employeeListDtos = ObjectMapper.Map<List<EmployeeListDto>>(employees);

            return new PagedResultDto<EmployeeListDto>(
                employeesCount,
                employeeListDtos
            );
        }

In the log it says missing map, but i am sure the map is there When i debug and put a watch on employees is says Status Faulted

If i put the same function in UserAppService it works

What am i missing?

I see that in the userappservice the filtering of the users is moved to a private function


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi

    You need use await

        var employees = await users
                    .OrderBy(input.Sorting)
                    .PageBy(input)
                    .ToListAsync();
    
  • User Avatar
    0
    rvanwoezik created

    Hi, yes await was missing, but now i get the following error in the log

    ERROR 2020-03-10 15:17:10,626 [27 ] Mvc.ExceptionHandling.AbpExceptionFilter - The LINQ expression 'DbSet<User> .Where(u => __ef_filter__p_0 || !(((ISoftDelete)u).IsDeleted) && __ef_filter__p_1 || ((IMayHaveTenant)u).TenantId == __ef_filter__CurrentTenantId_2) .Where(u => u.UserName != "admin") .OrderByDescending(u => u.HireDate) .OrderBy(u => u.PreferredFullName)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

  • User Avatar
    0
    maliming created
    Support Team
    • What is PreferredFullName?
    • What is input.Sorting?

    Does it work when you remove OrderBy(input.Sorting)?

  • User Avatar
    0
    rvanwoezik created

    When i remove the default sorting 'PreferredFullName' it works Thanks

    PreferredFullName is when people get married in the Netherlands they can chose how to use lastname, lastname type is an enum PreferredFullName is not stored in DB

    `[NotMapped] public virtual string PreferredLastName { get { _partnerFullLastName = GetLastName(PartnerSurName, PartnerSurNamePrefix); _birthFullLastName = GetLastName(Surname, SurnamePrefix);

                switch (PreferredLastNameType)
                {
                    case LastNameType.PartnerNaam:
                        _preferredFullName = _partnerFullLastName;
                        break;
                    case LastNameType.PartnerGeboorte:
                        _preferredFullName = _partnerFullLastName + " - " + _birthFullLastName;
                        break;
                    case LastNameType.GeboortePartner:
                        _preferredFullName = _birthFullLastName + " - " + _partnerFullLastName;
                        break;
                    default:
                        _preferredFullName = _birthFullLastName;
                        break;
                }
                return _preferredFullName;
            }
        }`
        
        thanks