diff --git a/csharp-linq/SelectVsSelectMany/SelectVsSelectMany.Tests/SelectManyTests.cs b/csharp-linq/SelectVsSelectMany/SelectVsSelectMany.Tests/SelectManyTests.cs index 27afc47c90..047f0b5b86 100644 --- a/csharp-linq/SelectVsSelectMany/SelectVsSelectMany.Tests/SelectManyTests.cs +++ b/csharp-linq/SelectVsSelectMany/SelectVsSelectMany.Tests/SelectManyTests.cs @@ -80,4 +80,26 @@ public void WhenUsingSelectManyToFlattenTheCollectionAndSubCollections_ThenColle Assert.That(detailedListOfEmployees[4], Is.EqualTo("Cedric | Development | Developer")); Assert.That(detailedListOfEmployees[5], Is.EqualTo("Monica | BackOffice | HumanResources")); } + + [Test] + public void WhenProjectingACollectionProperty_ThenSelectNestsAndSelectManyFlattens() + { + var employeeLists = _listOfDepartments.Select(d => d.Employees); // IEnumerable> + var employees = _listOfDepartments.SelectMany(d => d.Employees); // IEnumerable + + Assert.That(employeeLists.Count(), Is.EqualTo(3)); + Assert.That(employees.Count(), Is.EqualTo(6)); + } + + [Test] + public void WhenUsingASecondFromClauseInQuerySyntax_ThenItTranslatesToSelectMany() + { + var employees = from department in _listOfDepartments + from employee in department.Employees + select employee; + + var flattenedWithSelectMany = _listOfDepartments.SelectMany(department => department.Employees); + + Assert.That(employees, Is.EqualTo(flattenedWithSelectMany)); + } } \ No newline at end of file diff --git a/csharp-linq/SelectVsSelectMany/SelectVsSelectMany.Tests/SelectVsSelectMany.Tests.csproj b/csharp-linq/SelectVsSelectMany/SelectVsSelectMany.Tests/SelectVsSelectMany.Tests.csproj index 31bfb18ae4..726bccf6b4 100644 --- a/csharp-linq/SelectVsSelectMany/SelectVsSelectMany.Tests/SelectVsSelectMany.Tests.csproj +++ b/csharp-linq/SelectVsSelectMany/SelectVsSelectMany.Tests/SelectVsSelectMany.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net10.0 enable enable