I have a table whose primary key id is an identity column. I think that when a new record is created, id will be incremented by 1.
However I found that it is 0 while debugging. Why?
The necessary code:
public DbSet<testDetails> testDetailRecords { get; set; }
testDetails test = testContext.testDetailRecords.Create();
// test.id is 0 when hover over it
public class testDetails : IEntityWithRelationships
{
[Key]
[Required]
[Display(Name = "Primary Key", Description = "Primary Key")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long id { get; set; }
It is 0 because it is not created yet.
TestContext context = new TestContext();
var increment = context.IncrementTest.Create();
increment.name = "testbyme";
context.IncrementTest.Add(increment);
context.SaveChanges();
That works without throwing any exceptions for me.