Mark Chidlow
Mark Chidlow

Reputation: 1472

How do I work with a join table in LINQ?

Struggling with my LINQ for a many to many join table :-(

I have College, Student and StudentApplications entities.

A College has many StudentApplications

A Student has many StudentApplications (for a number of different Colleges)

How do I best get all the Students that have applied to a College?

I'd prefer to use Lambda expressions.

Or if you can point to a good online tutorial that could help me work it out myself even better!

EF Core BUG

While implementing based on the answer (thanks for that) I came across a bug in EF 7/Core in this area. I raised the following issue:

https://github.com/aspnet/EntityFramework/issues/5084

Upvotes: 0

Views: 62

Answers (1)

GazTheDestroyer
GazTheDestroyer

Reputation: 21241

students.Where(s => s.Applications.Any(a => a.College == searchCollege));

Upvotes: 2

Related Questions