efcore
efcore copied to clipboard
Explicit Interface Members and NotMapped]
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(); }
}