Skip to content

Don't let [NotMapped] on an explicit interface implementation ignore a public member - #39499

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
AsadIqbal-Dev:fix/notmapped-explicit-interface
Nov 3, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
AsadIqbal-Dev:fix/notmapped-explicit-interface

Conversation

@AsadIqbal-Dev

Copy link
Copy Markdown
Contributor
  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

Fixes #34242

NotMappedMemberAttributeConvention sees the attribute on the explicit implementation, whose member name is IBookCover2Haver.Covers, and calls Ignore with GetSimpleMemberName(), which is Covers. The ignore then removes the public Covers navigation, and Include(x => x.Covers) throws.

The convention now skips the ignore when the member's simple name differs from its full name and the type has another property or field with that simple name. Both the entity type and complex type paths do this. If there's no such member, nothing changes, so NotMappedAttribute_ignores_explicit_interface_implementation_property still passes.

If the public member should be ignored too, it can have its own [NotMapped].

Added NotMappedAttribute_on_explicit_interface_implementation_does_not_ignore_public_member to DataAnnotationTestBase. It covers a scalar property, a navigation and a property on a complex type, and fails without the change. EFCore.Tests, DataAnnotationInMemoryTest and the in-memory model builder tests pass with it.

…a public member

- NotMappedMemberAttributeConvention ignores members by simple name, so the attribute on IFoo.Covers also ignored the public Covers
- Skip the ignore when the type has another member with that name, for entity and complex types

Fixes dotnet#34242

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit 90e09cc into dotnet:main Nov 3, 2026
19 of 20 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Include with navigation collection with same name as other [NotMapped] property fails with InvalidOperationException

2 participants