I have Pin Model
public class Pin
{
[Key]
[Column("pin")]
public int Id { get; set; }
[StringLength(50, MinimumLength = 1)]
[Column("desc", TypeName = "varchar")]
public string Description { get; set; }
}
I have MyDbContext
public class MyDbContext : DbContext
{
public MyDbContext() : base("DbName")
{
Database.SetInitializer<MyDbContext>(new MyDbInitializer());
}
public virtual IDbSet<Pin> Pins { get; set; }
}
internal class MyDbInitializer : CreateDatabaseIfNotExists<MyDbContext>
{
protected override void Seed(MyDbContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
context.SaveChanges();
return;
}
}
I'm using MyDbContext for adding pins
var pin = new Pin{ Description = "Test description" };
using (var context = new MyDbContext())
{
context.Pins.Add(pin);
context.SaveChanges();
}
After SaveChanges is done the object pin has updated Id with value 1300 for example but according to database latest Id should be 1310 and 1300 is already busy. Bug appears only in one production environment, there was no possibility to reproduce on local or staging environments
Any advises about direction where to investigate is appreciated