Reputation: 2439
This is the scenario. I have the next class:
class A
{
string attribute1;
string attribute2;
List<B> attribute3;
}
class B
{
string attribute1;
}
And my program runs a:
list<Class A> myList
I want to get, filtering using linq, a specific list Class A
So, as far as I reach, I am getting a list or a list through:
myList.SelectMany(o => o.attribute3.Where(p => p.attribute1 == "test")).ToList()
myList.SelectMany(o => o.attribute3.Select(p => p.attribute1 == "test")).ToList()
Any clue? Thanks mates.
Upvotes: 1
Views: 58
Reputation: 1196
Just run:
myList.Where(o => o.attribute3.Any(p => p.attribute1 == "test")).ToList()
Upvotes: 1