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 9024901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:08:25+00:00 2026-06-16T06:08:25+00:00

This LINQ expression is not working: dt.AsEnumerable().ToDictionary<Int64, List<string>> ( dtRow => dtRow.Field<Int64>(CodeVal_1), new List<string>

  • 0

This LINQ expression is not working:

dt.AsEnumerable().ToDictionary<Int64, List<string>> (
    dtRow => dtRow.Field<Int64>("CodeVal_1"),
    new List<string> {
        dtRow => dtRow.Field<string>("CodeVal_2"), 
        dtRow => dtRow.Field<string>("CountryCode")
    }
);

dt is a DataTable, and I added a reference to DataSetExtensions.

Here full code

    using (DataSet dsIps = DbConnection.db_Select_Query("use mydb select * from tblCountryCodes"))
    {
        using (DataTable dt = dsIps.Tables[0])
        {
            dt.AsEnumerable().ToDictionary<Int64, List<string>>(
            dtRow => dtRow.Field<Int64>("CodeVal_1"),
            new List<string> {
                    dtRow => dtRow.Field<string>("CodeVal_2"), 
                    dtRow => dtRow.Field<string>("CountryCode")
                }
            );
        }
    }

errors 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-06-16T06:08:26+00:00Added an answer on June 16, 2026 at 6:08 am

    Based on the additional information, the problem is that you are not passing the right arguments to ToDictionary. It takes two lambdas, not a lambda and a List<>.

    Here’s the first step to fixed code:

    dt.AsEnumerable().ToDictionary(
        dtRow => dtRow.Field<Int64>("CodeVal_1"),
        dtRow => new List<string> {
            dtRow.Field<string>("CodeVal_2"), 
            dtRow.Field<string>("CountryCode")
        }
    );
    

    EDIT: fixed using wrong version of ToDictionary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help in turning this linq expression into a linq statment. SampleData.Publishers and
I am getting this error when I use the Linq expression of var emp
I have a GridView what I fill through a LINQ expression. Something like this:
I am having a real pain in converting this query expression into my LINQ
take this linq into consideration: list.Where(sil => sil.XML.Element(ticket) != null && sil.XML.Element(ticket).Attribute(id).Value == smsRequestIn.TicketID)
Hi I am trying to learn Linq, so I am not sure if this
I am attempting to select from a List using a linq expression where the
Please help this Linq newbie! I'm creating a list inside my class under test,
I have a List of String like List<String> MyList=new List<String>{A,B}; and a Dictionary<String, Dictionary<String,String>>
I have some trivial code that looks like this: SortedDictionary<String, long> d = 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.