-3

I have this code.

 var userListResult = from user in userList
                             from role in user.AspNetUsers.AspNetRoles
                             where role.Id == ((int)model.Roles).ToString()
                             select new UserManageViewModel.UserViewModel()
                             {
                                 Id = user.UserId,
                                 Email = user.AspNetUsers.Email,
                                 Name = user.FirstName + " " + user.LastName,
                                 IsAdviser = user.AspNetUsers.AspNetRoles.AsQueryable().Any(r => r.Id == ((int)eCareRoles.Adviser).ToString()),
                                 IsAdmin = user.AspNetUsers.AspNetRoles.AsQueryable().Any(r => r.Id == ((int)eCareRoles.Admin).ToString()),
                                 Company = user.UserCompanies != null ? user.UserCompanies.Name : String.Empty,
                                 Role = model.Roles,
                                 ListIfRoles = user.AspNetUsers.AspNetRoles.Select(x => x.Name).Aggregate((i, j) => i + "," + j)

                             };

I need to get in ListIfRoles string with comma. But I always get error "LINQ to Entities does not recognize the method 'System.String Aggregate[String](System.Collections.Generic.IEnumerable1[System.String], System.Func3[System.String,System.String,System.String])' method, and this method cannot be translated into a store expression."

I tried string.Join(",", list), tried convert to Array and then Join or Aggregate - but it always error.

Also i tried this`user.

AspNetUsers.AspNetRoles.Select(x => x.Name).AsEnumerable().Aggregate((i, j) => i + "," + j)

But error again. Help please.

ewqewqewqe
  • 51
  • 2
  • 9
  • `string.Join(",", user.AspNetUsers.AspNetRoles.Select(x => x.Name).ToArray())` - Join takes an array. – ProgrammingLlama May 31 '17 at 07:07
  • "LINQ to Entities does not recognize the method 'System.String Join(System.String, System.String[])' method, and this method cannot be translated into a store expression." – ewqewqewqe May 31 '17 at 09:03

1 Answers1

-2

you can try,

String.join(",",user.AspNetUsers.AspNetRoles.Select(x => x.Name).ToArray())
C.Fasolin
  • 313
  • 1
  • 4
  • 19
  • 1
    "LINQ to Entities does not recognize the method 'System.String Join(System.String, System.String[])' method, and this method cannot be translated into a store expression." – ewqewqewqe May 31 '17 at 09:03