실패 내 기지 :SaveChanges를 여기
그리고 그것은 하나의 영화 (ID를 외부의 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를 입력하려고하기 때문에 erroring인가? 이름이 고유해야한다는 것은 나타나지 않습니다. – dcreight