feat: add QueryableProjectionNullHandling option to skip projection null handling#2369
Open
fdipuma wants to merge 7 commits into
Open
feat: add QueryableProjectionNullHandling option to skip projection null handling#2369fdipuma wants to merge 7 commits into
fdipuma wants to merge 7 commits into
Conversation
…nNullHandling.Ignore
… handling is ignored
…and add coverage - NullMappedMemberSourceValue.Build: the Ignore short-circuit branch now requests addValuePropertyOnNullable so nullable value-type members (e.g. int? -> int) emit x.Member.Value instead of non-compiling x.Member. - MemberMappingBuilder: extract the duplicated IsIgnoredProjectionNullHandling predicate used for diagnostic suppression and inline null-handling mapping. - Add regression test for the value-type unwrap plus Verify coverage for a deeply nested nullable reference path and a nullable collection member under QueryableProjectionNullHandling.Ignore.
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.
Description
Adds a
QueryableProjectionNullHandlingmapper option that letsIQueryable<T>projection mappings skip null handling, for relational providers (e.g. EF Core) where the projection lambda is translated to SQL and never executed in memory.This implements part 3 of #2317 and should close:
CASEblocks nor reportsRMG002("no accessible parameterless constructor").#nullable enable/disable.Option
Set at mapper or assembly (
MapperDefaults) level:Under
Ignore, projection member access is emitted directly (x.Owner.Address.City,x.IntValue.Valuefor nullable value types) with no?., ternary!= null ? … : default, coalesce, or null fallback; theRMG089nullability diagnostic is suppressed. Nullable value-type members are unwrapped so the generated expression compiles. The defaultNullSafekeeps today's behaviour unchanged (non-breaking).note
The related idea from #2317 of honoring a conversion operator's own nullable annotations in non-projection mappings is intentionally not included here: it turned out to require changes to the shared member-mapping null-guard path and is best handled as a separate, focused PR. This PR is limited to the queryable-projection option.
Checklist