Throw on EF anti-patterns in tests and fix the ones found - #1421
Merged
Merged
Conversation
Add Verify.EntityFramework and enable ThrowOnAntiPatterns for every test SqlInstance. Fixes for what it found: - Connection count: the count ran on the page query, so it carried ordering, includes, split query and tracking options, all of which a count ignores. They are now stripped from the query's own chain before counting, stopping at any Skip or Take. - orderBy argument: it was applied as a second OrderBy after any ordering the resolver applied, which EF discards. The resolver's ordering is now removed first. This also drops a join the discarded ordering forced in Connection_without_first_or_last_returns_everything. Add OrderByArgumentReplacesResolverOrdering, over a new orderedParentEntities field, to cover the orderBy case for list fields.
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.
Adds Verify.EntityFramework (16.0.0-beta.4) to the tests and enables
ThrowOnAntiPatternsfor every testSqlInstance, then fixes what it found in the library.Fixes
Skip/Take, since below one the ordering decides which rows are counted.orderByargument. It was applied as a secondOrderByafter any ordering the resolver applied, and EF discards the first. The resolver's ordering is now removed before the argument's ordering is applied.Test changes
OrderByArgumentReplacesResolverOrderingtest, over a neworderedParentEntitiesfield whose resolver orders descending. It fails without theorderByfix.Connection_without_first_or_last_returns_everything: the join toParentEntitiesforced by the discardedOrderBy(_ => _.Parent)is gone from the SQL.SchemaPrint: includes the new field.