我正在尝试使用 Entity Framework 将实体插入到我的数据库中。见下文:
private void InsertarIntoDataBase()
{
Juego game = db.games.First(g => g.Id == anId);
Day d = new Day {
DayNumber = this.Number,
Game = game // This is a relationship. One Day has one game
};
db.AddToDay(d);
db.SaveChanges();
}
这总是用于插入,而不是更新。我第一次运行我的应用程序时,它可以工作,然后它停止工作,抛出这个异常An error occurred while updating the entries. See the InnerException for details.
。(我真的很确定我没有改变任何东西)。
为什么框架认为我正在更新?我错了什么?