title: EF Core 2.2 navigational property creating a duplicate entry
body: <p>For an <strong>existing Blog</strong> entity I'm adding a <strong>new Post</strong> with B<strong>log as a navigational property</strong>. The error is that a <strong>duplicate Blog</strong> is being inserted. Using <strong>EF Core 2.2</strong></p>
  
  <pre><code>class MyContext : DbContext
  {
      public DbSet&lt;Blog&gt; Blogs { get; set; }
      public DbSet&lt;Post&gt; Posts { get; set; }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;Post&gt;()
              .HasOne(p =&gt; p.Blog)
              .WithMany(b =&gt; b.Posts)
              .HasForeignKey(p =&gt; p.BlogId);
      }
  }
  
  public class Blog
  {
      public int BlogId { get; set; }
      public string Url { get; set; }
  
      public List&lt;Post&gt; Posts { get; set; }
  }
  
  public class Post
  {
      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; }
  }
  </code></pre>
  
  <p>PostFactory.cs</p>
  
  <pre><code>  public Post CreateNew(Guid id)
      {
          var post = new Post(id);
  
          return post;
      }
  </code></pre>
  
  <p>PostService.cs</p>
  
  <pre><code>   public Post Create(Guid blogId)
      {
          var blog = _context.Blogs.Include(t=&gt;t.Posts).FirstOrDefault(x =&gt; x.Id == blogId);
  
          var postFactory = new PostFactory();
          var post = postFactory.CreateNew(Guid.NewGuid());
  
          post.Blog = blog;
          post.BlogId = blogId;
  
          blog.Posts.Add(post);
          _context.SaveChanges();
          return post;
      }
  </code></pre>
  
  <p>Not sure why an existing Blog is again trying to be inserted into the DB. I get an error:</p>
  
  <p>Violation of PRIMARY KEY constraint 'PK_Blogs'. Cannot insert duplicate key in object 'dbo.Blogs' </p>