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

  • Home
  • SEARCH
  • 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 6978477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:45:45+00:00 2026-05-27T17:45:45+00:00

Please help the SQL Query in LINQ form – C# .NET 3.5 select distinct

  • 0

Please help the SQL Query in LINQ form – C# .NET 3.5

select distinct location, country from Customer where   Customer_Code ='1001';

This is Query has no problem. Works fine in SQL. But getting error while i used the below LinQ query in ASP.NET code in LINQ format. Please help the same.

EDIT:

In ASP.NET code,

    var Query2 =  ds.Tables[0].AsEnumerable()
                 .Where(p => p.Field<string>("Customer_Code") == "1001")
                 .Select(p => new {p.Field<string>("Location"),p.Field<string>("Country")});

ERROR:

Error: Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

Kindly help!!!

  • 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-27T17:45:45+00:00Added an answer on May 27, 2026 at 5:45 pm

    Something like:

    var query = dbContext.Customer
                         .Where(customer => customer.Customer_Code == "1001")
                         .Select(customer => new { customer.Location, customer.Country })
                         .Distinct();
    

    The key here is the use of an anonymous type that serves as a tuple holding a customer’s location and country.


    EDIT: After your edit, it looks like you are using data-tables, not LINQ to SQL / Entities.
    In which case, you probably want something like:

    var query = table.AsEnumerable()
                     .Where(p => p.Field<string>("Customer_Code") == "1001")
                     .Select(p => new 
                                   {
                                      Location = p.Field<string>("Location"),
                                      Country = p.Field<string>("Country")
                                   })
                     .Distinct();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please help convert the following into LINQ To SQL query? select *
Please help me with T-SQL query in SQL 2008 to get value from between
Can someone please help me tune this SQL query? SELECT a.BuildingID, a.ApplicantID, a.ACH, a.Address,
help me please with this simple E-sql query: var qStr = SELECT SqlServer.Month(o.DatePaid) as
Please help me to find out error in my SQL query. I have created
Please help me to prevent my data from SQL injection. I have replaced '
I am trying to convert a SQL query to LINQ. Somehow my count(distinct(x)) logic
I need to performance tune following SQL query by removing OR statements Please help
I have a t-sql query written with this sample help . SELECT t.gName AS
Please help me fetching google like url descriptions in just one SQL query. see

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.