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