LINQ query - issue with nested collection
-
I'm trying to learn som LINQ stuff. I'm playing around with some collection stuff, but have hit a problem with a nested collection. I have a collection of movie critics. Each critic have a collection of movies they have reviewed. I'm trying to find the vote for a specific movie for a specific critic: I have this:
var query = from critic in critics
where
critic.Name == "Hugo Bugo" && critic.MoviesReviewed.Any(m => m.Name == "Iron Man")
select m.Vote;Obviously I cannot do a "select m.Vote" since I cannot access the m variable from the lambda expression. But how do I get to that vote?
"When you have made evil the means of survival, do not expect men to remain good. Do not expect them to stay moral and lose their lives for the purpose of becoming the fodder of the immoral. Do not expect them to produce, when production is punished and looting rewarded. Do not ask, `Who is destroying the world?' You are."
-Atlas Shrugged, Ayn Rand -
I'm trying to learn som LINQ stuff. I'm playing around with some collection stuff, but have hit a problem with a nested collection. I have a collection of movie critics. Each critic have a collection of movies they have reviewed. I'm trying to find the vote for a specific movie for a specific critic: I have this:
var query = from critic in critics
where
critic.Name == "Hugo Bugo" && critic.MoviesReviewed.Any(m => m.Name == "Iron Man")
select m.Vote;Obviously I cannot do a "select m.Vote" since I cannot access the m variable from the lambda expression. But how do I get to that vote?
"When you have made evil the means of survival, do not expect men to remain good. Do not expect them to stay moral and lose their lives for the purpose of becoming the fodder of the immoral. Do not expect them to produce, when production is punished and looting rewarded. Do not ask, `Who is destroying the world?' You are."
-Atlas Shrugged, Ayn RandTry this:
var query = from critic in critics
where critic.Name == "Hugo Bugo"
from movie in critic.MoviesReviewed
where movie.Name == "Iron Man"
select movie.Vote;
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer