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

The Archive Base Latest Questions

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

If I wanted to return just the ID, and Name from a collection of

  • 0

If I wanted to return just the ID, and Name from a collection of Customer entities, what would be the recommended way of doing this? Should I use the Entity Set and then pick off what I need as I loop the collection? Is there LINQ syntax that can give me the equivalent of a SQL Select clause (i.e. Select ID, Name From Customer).

Thank you,
Stephen

  • 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-18T10:25:02+00:00Added an answer on May 18, 2026 at 10:25 am

    Use Queryable.Select<TSource, TResult> to project the collection:

    var customers = ctx
       .Customers
       .Where(x => x.FirstName == "Joe")
       .Select(x => new { ID = x.CustomerId, Name = x.CustomerName })
       .ToList();
    

    Note that will project the results into a List<T> of anonymous types.

    If you want to project it into something else (e.g custom class/POCO), you’ll need to materalize the result set first, and then project the query (e.g .ToList() and then .Select()).

    In other words, if you do this:

    var customers = ctx
           .Customers
           .Where(x => x.FirstName == "Joe")
           .Select(x => new CutDownCustomer { ID = x.CustomerId, Name = x.CustomerName })
           .ToList(); // fire query
    

    You will get an EF error (cannot be translated to Linq-Entities query – as “CutDownCustomer” is not part of the conceptual model).

    So you must do this:

    var customers = ctx
           .Customers
           .Where(x => x.FirstName == "Joe")
           .ToList() // fire query
           .Select(x => new CutDownCustomer { ID = x.CustomerId, Name = x.CustomerName });
    

    Of course, if you only require method scope for your result set, anonymous types should be sufficient.

    HTH.

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

Sidebar

Related Questions

if I wanted to return this from a class member function as reference would
If I wanted to do something like this: collection.each do |i| return nil if
I want to return multiple parameter from a method in c#.I just wanted to
If I have a function: function this($a){ return $a; } If I wanted to
Wanted to know if there was a way one could query shelveset details from
First off, just wanted to say I'm a novice at this type of coding,
I just wanted to share this Query class and get your thoughts on it.
While developing an application, I had the following problem. I wanted to return an
I wanted to test how C++ behaves when the return value of a function
If I wanted to make one request, but return multiple groups of responses, how

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.