0

我正在使用 EF6 和 MySQL.Data v6.9.5 连接到 MySQL 数据库。当我插入一条记录,调用 db.SaveChanges() 并引用记录的 ID 列时,我得到了一个看起来像有效的 ID,但由于某种原因,数据库中的 ID 会发生变化。

示例代码

var res = db.SampleRegs.Add(sample);
        try
        {
            db.SaveChanges();
            //now, to fire a trigger, we need to UPDATE the table and set Saved = 10; (trigger fires on UPDATE when Saved = 10).
            db.Entry(res).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            //Now set Saved = 20 to fire another trigger
            System.Threading.Thread.Sleep(100);//because reasons
            res.Saved = sbyte.Parse("20");
            db.Entry(res).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
        }

当我在 ID 字段上放置断点时res,例如值 128990。但是当我稍后直接检查 MySQL 表时,它将具有不同的 ID 值,似乎总是少 100 到 200,例如 12880。

我不知道这里发生了什么,因为我无法在我们的开发和测试环境数据库中复制这种行为,但是当我转向生产时,就会发生这种情况。我知道生产数据库处理特定表中的大量数据,如果这很重要的话。

4

0 回答 0