Th1sD0t
Th1sD0t

Reputation: 1119

Get collection containing a specific object out of a collection

I've to admit that the title is a little bit confusing.

I've got a collection which contains a collection which contains some properties.

Example:

public class LocationalLink {
    public Model.Location Location { get; private set; }
    public ObservableCollection<Converter.Link.RoomLockerLink> RoomCollection { get; private set; }
}

public class RoomLockerLink {
    public Model.Room Room { get; private set; }
    public ObservableCollection<Model.Locker> LockerCollection { get; private set; }
}

In my main application I've got a collection of LocationalLink.

Get collection containing a specific object our of a collection Now I'd like to get those RoomCollections which are containing a specific Room.

I thought this could be something like that:

RoomCollection = LocationalLinkList.Where(o => o.RoomCollection.Where(i => i.Room == obj));

I know this doesn't work because the second Parameter of the Where-clause has to be a boolean expression. May anyone could give me a hint?

Upvotes: 0

Views: 61

Answers (1)

ASh
ASh

Reputation: 35679

change 2nd Where method to Any

RoomCollection = LocationalLinkList.Where(o => o.RoomCollection.Any(i => i.Room == obj));

Upvotes: 3

Related Questions