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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:58:46+00:00 2026-06-16T22:58:46+00:00

I need to return a number of Linq query results into a List object

  • 0

I need to return a number of Linq query results into a List object based on a foreign key value. What is the syntax for doing this? I am new to using Linq, so below is my best guess so far. I receive an error in the .Where() “clause” stating “The name ‘pt’ does not exist in the current context. Any help would be greatly appreciated!

        List<AgentProductTraining> productTraining = new List<AgentProductTraining>();

        var prodCodes = productTraining.Select(pt => new[]
                                                         {
                                                             pt.ProductCode,
                                                             pt.NoteId,
                                                             pt.ControlId
                                                         })
                                                         .Where(pt.CourseCode == course.CourseCode);
  • 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-16T22:58:47+00:00Added an answer on June 16, 2026 at 10:58 pm

    You would need to switch the locations of where and select if you’re using extension methods:

    var prodCodes = productTraining.Where(pt => pt.CourseCode == course.CourseCode)
                                   .Select(pt => new SomeRandomType
                                                             {
                                                                 ProductCode = pt.ProductCode,
                                                                 NoteId = pt.NoteId,
                                                                 ControlId = pt.ControlId
                                                             });
    

    I also recommend, as you can see above, that you create a type for that select statement so that you’re not relying on anonymous types. You should put in into an object type that you know everything about.

    Also, if CourseCode is a string, that should be pt.CourseCode.Equals(course.CourseCode).

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

Sidebar

Related Questions

I need help constructing a linq query that will return a list of usernames
The DataContext.GetTable() method will return an object of type: System.Data.Linq.Table By doing that, I
I currently have a SQL query that returns a number of fields. I need
I need to return an a generic list in the correct order for my
i need to return a JSON with this format: {answers: [{id: 93, value:Ahstron}, {id=94,
I need to return a list of counties, but I need to filter out
I need to return two values at a time, so I have: class IterableObject(object):
I have a LINQ query that uses 1 table + a large number of
I've got a situation where I need to have my LINQ to Entities query
I have a LINQ entity that I need to create a special string value

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.