Ensure that enumerable expressions are materialized early in funcletization
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
Users can embed enumerable expressions inside queries:
```c#
var ids = new[] { 1, 2, 3 }.Where(i => i > 1);
_ = await context.Blogs.Where(b => ids.Contains(b.Id))...
```
This results in an IEnumerable-typed query parameter.
We then have various scenarios where we deal with such parameters. Specifically, in SqlNullabilityProcessor we enumerate IEnumerable parameters, e.g. when inlining constant/parameter lists into SQL when Contains is specified (in SqlNullabilityProcessor).
Ideally, we'd materialize these IEnumerable parameter in the earliest stage of the query pipeline - the funceltizer. Once that's done, the rest of the query pipeline can assume that everything is already materialized, and enumeration is cheap and can be done multiple times if needed (even though these would still likely be typed as IEnumerable).
One problem here is that .NET doesn't have a single (materialized) collection interface/type; collections can implement non-generic `ICollection`, generic `ICollection` and `IReadOnlyCollection`. strings incidentally implement IEnumerable but none of the collection interfaces, even though they're materialized. This makes it difficult to abstract over materialized collections and work with them.
Contributor guide
Assessment
This issue has not been assessed yet.