Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit Interface Members and NotMapped] #33675

Closed
DynConcepts opened this issue May 3, 2024 · 1 comment
Closed

Explicit Interface Members and NotMapped] #33675

DynConcepts opened this issue May 3, 2024 · 1 comment

Comments

@DynConcepts
Copy link

Adding [NotMapped] Explicit Interfaces definitions breaks code.

Modify the Sample for "Saving Related Objects" to add the following interfaces]

The code will no longer Persist Post instances.

    public interface IBlog
    {
        List<IPost> Posts { get; set; }
    }
    public interface IPost
    {
        IBlog? Blog { get; set; }
    }
    public class Blog : IBlog
    {
        public int BlogId { get; set; }
        public string Url { get; set; }

        public List<Post> Posts { get; set; }

        [NotMapped]
        List<IPost> IBlog.Posts { get; set; }
    }

    public class Post : IPost
    {
        public int PostId { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }

        public int BlogId { get; set; }
        public Blog Blog { get; set; }

        [NotMapped]
        IBlog IPost.Blog { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
    }
@AndriySvyryd
Copy link
Member

This is by design, EF assumes that the property names are unique within a type, so [NotMapped] applies to all properties with the same name on that class.

@AndriySvyryd AndriySvyryd closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2024
@AndriySvyryd AndriySvyryd removed their assignment May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants