title: How to create entity with foreign keys in ef core and avoid IDENTITY_INSERT error
body: <p>I have entity with foreign keys <code>Project</code>:</p>
  <pre><code>public class Project : IEntity
  {
      public int Id { get; set; }
  
      public int? TypeId { get; set; }
      public virtual Type? Type { get; set; } = null!;
  
      // other properties...
  }
  </code></pre>
  <p>I want to create a new object (insert a new entity into the database):</p>
  <pre><code>await Context.Set&lt;TEntity&gt;().AddAsync(entity);
  </code></pre>
  <p>And I have the following problem:</p>
  <blockquote>
  <p>Microsoft.Data.SqlClient.SqlException (0x80131904): It is not possible to insert an explicit value for the identifiers column in the
  &quot;Types&quot; table when the IDENTITY_INSERT parameter is set to OFF.</p>
  </blockquote>
  <p>So, when trying to execute this SQL query, I have an exception:</p>
  <pre><code>SET NOCOUNT ON;
  INSERT INTO [Types] ([Id], [Name])
  VALUES (@p0, @p1);
  </code></pre>
  <p>There's no need to create a new <code>Type</code> in the <code>Types</code> table. How can I fix this? I understand that I can set IDENTITY_INSERT to OFF, but I think this isn't a good practice.</p>