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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:38:33+00:00 2026-06-07T22:38:33+00:00

Link to this two topics: Convert Lambda Expression of a query to linq version

  • 0

Link to this two topics:

Convert Lambda Expression of a query to linq version

and

return items that all records related to that items have specific conditions

in first topic @xanatos comment that :

@Kerezo Be aware that the new { r.City } error appears twice (once in each query). new { r.City } creates an anonymous object with a single property called City that contains the City object (so you are wrapping your City in an object) Without the new you have directly the City

consider this code:

var citiesToExclude = from r in ent.TestAllStatusEqualsOnes
                              where r.Status != 1
                              select r.City;

GridView1.DataSource = citiesToExclude;
GridView1.DataBind();

if I wrote this code in this way:

var citiesToExclude = from r in ent.TestAllStatusEqualsOnes
                              where r.Status != 1
                              select new { r.City };

GridView1.DataSource = citiesToExclude;
GridView1.DataBind();

every thing are equal.

I don’t understand what is the differencr between select r.Field and select new {r.Field}. can any one explain more?

thanks

  • 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-07T22:38:35+00:00Added an answer on June 7, 2026 at 10:38 pm

    Anonymous types are pretty much the same as any other type. So:

    select new { r.City }
    

    is pretty much identical to:

    select new SomeType { City = r.City}
    

    with:

    class SomeType { public string City {get;set;} }
    

    This then, perhaps makes the distinction simple; it is same as the difference between:

    string x = obj.City;
    

    and

    SomeType y = new SomeType { City = obj.City };
    

    In one case, what you are obtaining is the city name. In the other case, you are obtaining an object that has a property called City which is the city name (although it could, in the general case, have other properties too).

    The same logic applies inside LINQ.

    One handy difference between the two is considering null, for example:

    var city = {some query}.FirstOrDefault();
    

    if you are selecting the actual city name, it is a bit hard to tell the difference between “no row” vs “a row, with a null city name”. If you are selecting an object, you can tell between obj == null vs obj.City == null.

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

Sidebar

Related Questions

This link shows you that jQuery uses (new Function(return + data))(); for older browsers,
In my controller I have two functions that pull all records from the db
This is a link to a question I had asked two days back, How
In this link: http://css-tricks.com/snippets/jquery/jquery-plugin-template/ it has a line of code that says // Add
I saw two related questions about this topic - one has an old link
I have this link: <a class=btn disabled id=next >&gt;&gt;</a> It has two classes btn
I'm trying to make custom Notifications in Android, following that link : http://developer.android.com/guide/topics/ui/notifiers/notifications.html This
Hi guys i'm trying to retrieve the link between this two tag eg text
For example on any tinyurl/ajdeijad link (this one is fake), the think redirects to
This link shows how to inject JavaScript code to WebView object in Android. However

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.