efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Explicit Interface Members and NotMapped]

Open DynConcepts opened this issue 1 year ago • 0 comments

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(); }
    }

DynConcepts avatar May 03 '24 16:05 DynConcepts