3
我試圖更新實體,但我收到以下錯誤:實體框架更新 - 上下文當前沒有跟蹤實體
The context is not currently tracking the entity.
我的數據庫表包括以下字段:
fixturedate, leagueID (FK), Team A (FK), Team B (FK).
我的代碼如下:
public void UpdateFixture(Fixture validFixture)
{
Fixture fixture = new Fixture();
fixture = entities.Fixtures.Where(f => f.fixtureId == validFixture.fixtureId).FirstOrDefault();
League league = new League();
league.LeagueId = validFixture.leagueId;
fixture.League = leagueActions.GetLeague(league);
fixture.Team1 = teamActions.GetTeam(validFixture.teamA);
fixture.Team2 = teamActions.GetTeam(validFixture.teamB);
entities.UpdateObject(validFixture);
entities.SaveChanges();
}
當我做entities.AttachTo("Fixtures", validFixture);
我得到的弗洛翼錯誤:
The context is already tracking a different entity with the same resource Uri.
我需要做什麼來更新燈具實體?
嗨Carko,你說得對。不得不更新實際夾具!非常感謝 – Johann 2011-12-17 23:27:41