Im saving some locations/cities in my database.
My locations/cities DOES get saved althrough my this._entities.SaveChanges(); throws an execption that goes something like:
The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message:AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.
I dont really know whats the problem since it worked before and this changes should not affect it really…
Here’s some code:
First off i get all the objects into currentLocation.
I loop them through a foreach to add item to method Add().
Last i call for _entites.SaveChanges(). Everything gets saved but i get an error…
var webService = new WeatherWebService();
currentLocation = webService.FindLocation(city);
// ...save the user in the database.
foreach (var item in currentLocation)
{
this._repository.Add(item);
}
this._repository.Save();
public override void Add(Location location)
{
this._entities.Locations.AddObject(location);
}
public override void Save()
{
this._entities.SaveChanges();
}
Problem sloved, seems you have to output a id from the Auto Increment… else it will make each post id 0 and therefor it thinks its several with same ID.
Used something like NewId as @@SCOPE_IDENTIY