Open jbhelm opened 1 year ago
@jbhelm I'm also able to reproduce this using .NET 6 and EF Core 6...
Hi @StefH
I didn't try it with any earlier versions of EF Core. However, I can say it does work with "classic" EntityFramework 6.4.4 on .NET 7.
Just want to add to this that I've found, as a work around, that adding Select(it) to the SelectMany() expression works. For example change:
context.Roots.Select("Children.SelectMany(Grandchildren)").ToDynamicArray() // <-- throws
to
context.Roots.Select("Children.SelectMany(Grandchildren.Select(it))").ToDynamicArray(); // <-- works
...or even better, use AsEnumerable()
:
context.Roots.Select("Children.SelectMany(Grandchildren.AsEnumerable())").ToDynamicArray(); // <-- works
1. Description
When calling
SelectMany()
within a Dynamic LINQ expression for anICollection<>
property, an ArgumentException is thrown when executed on EF Core 7 LINQ to Entities. Note that it does work on LINQ to Objects, LINQ to Entities with EF 6 (classic), and on EF Core 7 if the properties are declared asIEnumerable<>
instead ofICollection<>
.2. Exception
3. Fiddle or Project
4. Any further technical details
Thanks!