|
CombinedProjectionDefinition.Render() method throws StackOverflowException when including a huge number of fields.
Here is a unit test reproducing the error:
[Fact]
|
public void Include_Many_Fields()
|
{
|
var subject = CreateSubject<Person>();
|
|
var projection = subject.Include(x => x.FirstName);
|
var expectedProjection = new StringBuilder("{fn: 1");
|
for (int i = 0; i < 10000; i++)
|
{
|
var field = $"Field{i}";
|
projection = projection.Include(field);
|
expectedProjection.Append($", {field}: 1");
|
}
|
expectedProjection.Append("}");
|
|
Assert(projection, expectedProjection.ToString());
|
}
|
To fix the isuue I changed the constructor of the CombinedProjectionDefinition class to "unwind" the _projections collection to avoid recursively calling the Render() method:
public CombinedProjectionDefinition(IEnumerable<ProjectionDefinition<TSource>> projections)
|
{
|
_projections = Ensure.IsNotNull(projections, nameof(projections))
|
.SelectMany(projection => (projection as CombinedProjectionDefinition<TSource>)?._projections ?? new List<ProjectionDefinition<TSource>> { projection })
|
.ToList();
|
}
|
Let me know if you need more information to fix the issue or if you want me to also create a pull request.
|