public IEnumerable <AccountTypeWithAccountsResponseModel> GetAccountTypesWithAccountsAsync([FromQuery] string typed, string investmentToolId) { var accountDto = _repository.GetWithAccounts(_identityService.GetUserName(), typed, investmentToolId); var accountTypeGroup = accountDto.GroupBy(a => new { a.AccountTypeName, a.AccountTypeId }) .Select(g => new AccountTypeWithAccountsResponseModel() { AccountTypeName = g.Key.AccountTypeName, Id = g.Key.AccountTypeId }).ToList(); foreach (var g in accountTypeGroup) { g.Accounts = accountDto.Where(at => at.AccountTypeName == g.AccountTypeName) .ProjectTo <AccountLookupResponseModel>(_mapper.ConfigurationProvider).ToList(); } return(accountTypeGroup); }