title: EF core: cannot insert object with foreign key using ID properties (only navigation properties work)
body: <p>I'm using Entity Framework Core to create my (code first) database model.<br>
  In the model I have these classes:</p>
  
  <pre><code>[Table("groups")]
  public class Group {
      public int? Id { get; set; }
      [JsonIgnore]
      public virtual ICollection&lt;Membership&gt; Members { get; set; }
  }
  
  [Table("identities")]
  public class Identity {
      public int? Id { get; set; }
      [JsonIgnore]
      public virtual ICollection&lt;Membership&gt; MemberOf { get; set; }
  }
  
  [Table("memberships")]
  public partial class Membership {
      [Column("group_id")]
      public int GroupId { get; set; }
      [Column("identity_id")]
      public int IdentityId { get; set; }
      [JsonIgnore]
      public virtual Group Group { get; set; }
      [JsonIgnore]
      public virtual Identity Identity{ get; set; }
  }
  </code></pre>
  
  <p><code>Membership</code> is a many-to-many relationship between <code>Group</code> and <code>Identity</code>.<br>
  I have configured the relationship using the fluent API like this:</p>
  
  <pre><code>protected override void OnModelCreating(ModelBuilder modelBuilder) {
      var entity = modelBuilder.Entity&lt;Membership&gt;();
      entity.HasKey(e =&gt; new { 
          e.GroupId, 
          e.IdentityId }
      ).HasName("PK_identity_memberships");
      entity.HasOne(d =&gt; d.Group)
          .WithMany(p =&gt; p.Members)
          .HasForeignKey(d =&gt; d.GroupId)
          .HasConstraintName("memberships_group_id_fkey");
      entity.HasOne(d =&gt; d.Identity)
          .WithMany(p =&gt; p.MemberOf)
          .HasForeignKey(d =&gt; d.IdentityId)
          .HasConstraintName("memberships_identity_id_fkey");
  }
  </code></pre>
  
  <p>My problem is that if I try to insert a <code>Membership</code> in the DB setting <code>GroupId</code> and <code>IdentityId</code> with valid values, I get this error:</p>
  
  <p>Npgsql.PostgresException: 23503: insert or update on table "memberships" violates foreign key constraint "memberships_group_id_fkey"</p>
  
  <p>To insert a <code>Membership</code> object, I need to set the <code>Group</code> and <code>Identity</code> navigation properties, and then everything works fine.</p>
  
  <p>Is there a way to insert new objects without using the navigation properties?</p>