私のデータベースにいくつかの場所/都市を保存しています。
私の場所/都市 this._entities.SaveChanges();
は、次のような実行をスローすることで保存されます。
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.
以前は機能していたので、問題が何であるかはわかりません。この変更は実際には影響しないはずです...
ここにいくつかのコードがあります:
最初に私はすべてのオブジェクトをcurrentLocationに入れます。それらをforeachにループさせて、メソッドAdd()にアイテムを追加します。最後に、_entites.SaveChanges()を呼び出します。すべてが保存されますが、エラーが発生します...
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();
}