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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:56:24+00:00 2026-06-04T15:56:24+00:00

I have this small application that I’m building as an exercise to learn the

  • 0

I have this small application that I’m building as an exercise to learn the basics of the Entity Framework. It uses a MySQL db with 3 tables: Courses, Students and Students_has_Courses:
DB Schema

I used this db to create an Entity model in Visual Studio:
VS Schema

It’s working fine. I can bind a table with my datagridview, modify data and press a button to save the changes. But as you see, the Students_has_Courses is an association (this is pretty new to me). And now my question: I need every Course ID for a specified student ID (to know which courses a student is taking). I thought this LINQ query would be fine:

var query = from s in school.Students.AsEnumerable()
            where s.ID == selectedStudentId
            select s.Courses;

But I can’t really seem to extract the Course ID’s from this EntityCollection ? I used a foreach(var course in query) but I’m really stuck 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-04T15:56:25+00:00Added an answer on June 4, 2026 at 3:56 pm

    You should be able to get the course IDs by using:

    var studentsCourseIDs = (from s in school.Students
                             where s.ID == selectedStudentId
                             select s.Courses.Select(c => c.ID))
                            .Single();
    

    Alternatively you start from the Courses set:

    var studentsCourseIDs = (from c in school.Courses
                             where c.Students.Any(s => s.ID == selectedStudentId)
                             select c.ID)
                            .ToList();
    

    Don’t use the AsEnumerable() in your example because it will load the whole students table into memory before the where clause and the selection is applied.

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

Sidebar

Related Questions

Work on this small test application to learn threading/locking. I have the following code,
I have a small application that uses the same API as the powerscript examples
I have this idea for a small-medium web application that I would like to
I have manage to create a small size js application that uses jQuery and
I have a small application that uses a navigation window and a set of
I'm building a small application that pulls statistics from an API I have no
I have a small application that I have written that uses the MVP pattern
I have a small application that uses a DrawingArea to draw a simple map
In my c# application i have this small form which is used to set
we have a small flash component on our website/application to upload multiple files. This

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.