Basically I have a list of objects. Let's call them meetings. Inside the meetings there is another list of objects. Let's call those participants. I want to return all meetings where a certain participant is in the list.
I want something like this:
meetings.Where(meeting => meeting.Participants.Name == "Test name").ToList();
Basically return a list of meetings, where the meeting has a participant with the name "Test name".
EDIT: I actually ended up using a MongoDB filter. Before I would just extract all the "meetings" (with a filter) and then use LINQ to filter the list. Might as well filter out the results on database level.. But this is good to know.
Are you looking for Any?
var result = meetings
.Where(meeting => meeting
.Participants
.Any(participant => participant.Name == "Test name"))
.ToList();
You can use LINQ method Any and this one line of code :
var result = meetings.Where(m => m.Participants.Any(p => p.Name == "Test name")).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With