none
Linq query outputting curly braces '{ }' in output RRS feed

  • Question

  • I am trying to query a database with Linq EF6 but getting '{ }' in my output. below is my code. Any help will be appreciated.

      var exportToexcel = data.admin.AsQueryable()
                .Include(x => x.employees.contractors)                 
                .Include(x => x.employees.contractorRoles) 
                .Where(x => x.employees.contractors.Id == 60);
    
                var roles = exportToexcel.Select x => new
                {
                 managers = string.Join(",", x.employees.contractorRoles.Where(a => a.contractorROLE.RoleId == 6)
               .Select(r => new
                {
                    S = r.User.Lastname + "/" + r.User.Firstname
               }).Distinct()),


    Ebenezer

    Thursday, November 7, 2019 6:38 PM

Answers

  • Hi 

    Thanks for the response. The output is not empty so it is not that I have a bug. The output is adding

    {tom.jame, Micheal Anthony}. I don't want the {}. That is my issue, hence the question


    Ebenezer

    Where did you get the "output"? By "add watch"? If so, that's just normal. When you use the foreach statement to iterate over it, it won't be accompanied by "{}".

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by denkyira Friday, November 8, 2019 5:25 PM
    Friday, November 8, 2019 5:08 AM
    Moderator

All replies

  • Hi denkyira,

    Just according to the code, it is hard to re-create the situation you described.

    So, the only way to solve this problem is to try to separate each Select statement. Check if their values are empty by breakpoints.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 8, 2019 1:46 AM
    Moderator
  • Hi 

    Thanks for the response. The output is not empty so it is not that I have a bug. The output is adding

    {tom.jame, Micheal Anthony}. I don't want the {}. That is my issue, hence the question


    Ebenezer

    Friday, November 8, 2019 3:16 AM
  • Hi 

    Thanks for the response. The output is not empty so it is not that I have a bug. The output is adding

    {tom.jame, Micheal Anthony}. I don't want the {}. That is my issue, hence the question


    Ebenezer

    Where did you get the "output"? By "add watch"? If so, that's just normal. When you use the foreach statement to iterate over it, it won't be accompanied by "{}".

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by denkyira Friday, November 8, 2019 5:25 PM
    Friday, November 8, 2019 5:08 AM
    Moderator
  • Hi

    Once again thanks for the response. The output is not from By "add watch". It is the real output to the screen. I know when I use foreach it will solve my issue, but the question is how do I do foreach in this Linq query?


    Ebenezer

    Friday, November 8, 2019 12:44 PM
  • Hi Kyle

    You are right the the foreach loop works


    Ebenezer

    Friday, November 8, 2019 5:25 PM