✅ Nested from clause in query syntax
Hello guys, can someone explain the use of the nested
from
clause in the code above please. Why do we use nested from? Couldn't we just use the dot notation, like country.Cities? Why would it matter here?8 Replies
you have a list of countries... every country has a list of cities.. you want every city that has a population > 10000
what you have written or copied is called a linq query. its specifically for querying datastructures (and db cough)
It's "flattening" the cities into one sequence.
So you end up with one list of cities, instead of a list of lists of cities.
In method syntax this would be
Equivalent in regular LINQ would be
Ninja'd
yep I see
hmm I was trying to know how the structure would be with a single from clause, say we want to select only countries, so we have something like
Does the list become something this:
I'm a bit confused because of the curly braces... I know we use them for object initializer but here we want to represent them in the list, is it actually how it appears internally ?
is the same as
Also, where are you getting that from?
oh ok
I asked chatGPT to show me how it would appear but I guess it was wrong :c
but hmm I have a question, consider this from Microsoft Docs:
I tried it on my IDE and I obtained the output mentioned, which is correct but the thing is, why do we have the
{}
I'm confused about that
Oh ok that's because City was declared using record
?Yes.
record
supplies a ToString
that does that.Yep I see, it's clearer now, thanks !!