0

I'm new at linq and need for your advice.

I created three tables.

STUDENT ---- STUDENT_COURSE ----- COURSES

Database Diagram

I simply want to list which students are taking which courses.

If I'm using dbml to doing this, I get the result in somehow like below.

var takencourses = from sc in dbe.STUDENT_COURSEs
               join s in dbe.Students on sc.SID equals s.ID
               join c in dbe.COURSEs on sc.CID equals c.Id
               select new { s.NAME, s.SURNAME, c.COURSENAME};

dataGridView1.DataSource = takencourses;

But I'm not able to run this with Entity Data Model.

When I'm adding entity data model STUDENT_COURSE table is disappearing and its adding references on the tables like below.

Entity Data Model diagram

Because I didn't have the STUDENT_COURSE table I couldn't write the LINQ for joining Student and Courses tables to get the result.

I simply want to take NAME, SURNAME, COURSENAME from Entity Data Model.

  1. So how can I do it with using Entity Data Model?
  2. What should be the equivalent lambda code for this? For Example I tried something like this dbe.Students.SelectMany(s => s.STUDENT_COURSEs).ToList() but I didn't find the correct result.
  3. If I'm going to working on 100.000 rows, what will be the best choice for performance issues?

Thanks for your answers.

Alexander Chef
  • 378
  • 1
  • 2
  • 13
  • Either `from s in dbe.Students from c in s.COURSES select ...` or `from c in dbe.Courses from s in c.Student select ...` It would be nice if you use better class/navigation property names. – Ivan Stoev Mar 03 '18 at 16:06
  • It is worked. Thanks. What about the other questions? – Alexander Chef Mar 04 '18 at 07:16
  • You're asking too many questions for one post. I consider [this](https://stackoverflow.com/q/30466696/861716) a duplicate. – Gert Arnold Mar 04 '18 at 09:40

0 Answers0