From the course: .NET Essentials: LINQ for Databases

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Flatten child collections with SelectMany

Flatten child collections with SelectMany - .NET Tutorial

From the course: .NET Essentials: LINQ for Databases

Start my 1-month free trial

Flatten child collections with SelectMany

- [Narrator] We have seen that the navigation properties in Entity Framework, are useful for getting related information for an entity model. And here's an example, where I dumped out the regions information, and I can see there is the region ID column, and the region description column. And then through the navigation property, I can read more details about how many territories are part of the Eastern region. So there are 19 territories that are in that region, and in the Western region, I've got 15 territories. So that's useful, but you notice how they're in basically a sub collection, they're in a hash set, and that can sometimes make it harder to query or show the results. So I like using this method called select many, which is used to flatten this one to many relationship. Let me show you another example here, before I flattened it, is I'm going to write this query from r in regions, select r the…

Contents