Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6071275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:01:43+00:00 2026-05-23T10:01:43+00:00

I have a list here generated from a long query which the data is

  • 0

I have a list here generated from a long query which the data is used to pump to a report.

var result =  
  from..
  where..
  select new  { sale.Id, Username  = u.Name, Amount = p.amount};
output  = result.Tolist();

However, i would like to get rid of that long query by creating my own list of value instead. So i create a dictionary to store the key and value.
My purpose is to convert a dictionary back to a list which has the same output like the query above so that it can be pumped to my report

 public static object GetSalesDataBySaleOrderID(SaleOrder sale)
    {
        List<KeyValuePair<string, object>> list = new List<KeyValuePair<string, object>>();

        for (int i = 0; i < sale.saleOrderItem.Count(); i++)
        {             
            Dictionary<string, object> result = new Dictionary<string, object>()
            {
               {sale.Id.ToString(), sale.Id},                
               {"UserName", sale.User.GetSingleUserById(sale.saleOrderItem[i].UserId).Name},
               {"Amount", sale.saleOrderItem[i].Amount},                   
            };

            list.Add(result);
        }

        return list;
    }

I got an error at list.Add(result);

Error 5 Argument ‘1’: cannot convert from ‘System.Collections.Generic.Dictionary’ to ‘System.Collections.Generic.KeyValuePair’

—EDIT————
I have changed to List<Dictionary<string, object>> list = new List<Dictionary<string, object>>(); and it solved my error.

However i am still getting the value in dictionary format
enter image description here

This should be the intended output format in List
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:01:43+00:00Added an answer on May 23, 2026 at 10:01 am

    I’m not quite sure what you are trying to achieve to translate the whole thing into a key-value pair list when you actually want a list of objects back. Your function as given can be reduced to:

    public static object GetSalesDataBySaleOrderID(SaleOrder sale)
    {
        return sale.saleOrderItem
                   .Where(s => s != null)
                   .Select(s => new { 
                                      Id = s.Id,
                                      Username = sale.User.GetSingleUserById(s.UserId).Name,
                                      Amount = s.Amount 
                                    })
                   .ToList();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dropdownlist generated from db. Here is the result from page source.
I have a List generated from JSON data in Sencha Touch. Essentially, the list
I have already created a report using list of data from my database. i
I have a list view which is populated via records from the database. Now
I have a long list of domain names which I need to generate some
I have a PHP generated form which consists of a list of items, each
I have a generic list of objects in C#, for example sake, here's what
I have a list, each item of which has several things in it, including
Ok, so here's what I've got: I have a list of elements cached in
I have found this example on StackOverflow: var people = new List<Person> { new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.