這裏是我的基地:的SaveChanges失敗
而且它包含一個電影(IDS來自外部REST API):
Movie movie = Movie.CreateMovie(999, "MyFirstMovie");
movie.Kinds.Add(Kind.Create(123,"Adventure"));
movie.Kinds.Add(Kind.Create(124,"Comic"));
movie.Actors.Add(Person.Create(321,"John Wayne"));
movie.Directors.Add(Person.Create(120,"John Woo"));
_context.AddToMovies(movie);
_context.SaveChanges();
現在,當我試圖插入一個新的電影,我經常得到一個異常,說我插入一個已經存在於基地的實體。
想我有另外一個 「冒險」 的電影:
// Here all data comes from an external source and have no control over it.
using(Stream stream = myExternalStream)
{
Movie movie = Unserialize(stream);
_context.AddToMovies(movie);
}
// throws the exception because the kind "Adventure" already exists
_context.SaveChanges();
我怎樣才能避免這種例外?
難道示數,因爲你正在試圖進入同一KindID?它似乎沒有名稱需要是唯一的。 – dcreight