I'm trying to insert a entity into my database with Entity Framework. See below:
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();
}
This is always for an insert, not an update. The first time that I run my app, it works, afterwards it stops working, throwing this exception An error occurred while updating the entries. See the InnerException for details.. (I'm really sure that I did not change anything).
Why does the framework think I'm updating? And what am I wrong?