Refactor the state of include expressions as OneOrMany.#510
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the state management for include expressions and include strings to use the OneOrMany generic type, addressing issue #506. Key changes include refactoring Specification.cs to use OneOrMany for include state, updating the IncludeEvaluator and IncludeStringEvaluator to handle the new state, and adding tests for include scenarios.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Ardalis.Specification.EntityFrameworkCore.Tests/Evaluators/IncludeStringEvaluatorTests.cs | Added a test to verify query behavior when no include string is provided. |
| tests/Ardalis.Specification.EntityFrameworkCore.Tests/Evaluators/IncludeEvaluatorTests.cs | Added tests to verify behavior for specs with no or a single include expression. |
| src/Ardalis.Specification/Specification.cs | Refactored include state from List to OneOrMany, updating add and copy functionality. |
| src/Ardalis.Specification.EntityFrameworkCore/Evaluators/IncludeStringEvaluator.cs | Updated evaluator to check OneOrMany include strings for optimized processing. |
| src/Ardalis.Specification.EntityFrameworkCore/Evaluators/IncludeEvaluator.cs | Updated evaluator to check OneOrMany include expressions and use caching for delegates. |
Comments suppressed due to low confidence (2)
src/Ardalis.Specification.EntityFrameworkCore/Evaluators/IncludeStringEvaluator.cs:16
- [nitpick] Ensure that the SingleOrDefault property on OneOrMany returns null when there are multiple elements so that the fallback loop is reliably executed. If not already documented, please clarify this behavior in the OneOrMany API documentation.
if (spec.OneOrManyIncludeStrings.SingleOrDefault is { } includeString)
src/Ardalis.Specification.EntityFrameworkCore/Evaluators/IncludeEvaluator.cs:46
- [nitpick] Confirm that the SingleOrDefault property on OneOrMany returns null when more than one include expression is present so that the subsequent iteration over IncludeExpressions properly handles multiple items. Consider documenting this behavior for future maintainers.
if (spec.OneOrManyIncludeExpressions.SingleOrDefault is { } includeExpression)
This was referenced Aug 20, 2025
Closed
Closed
Closed
Closed
Closed
This was referenced Jan 9, 2026
This was referenced Jan 18, 2026
Open
This was referenced Jan 30, 2026
This was referenced Feb 9, 2026
Open
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It addresses the issue #506