次の流暢な API 構成を持つ Sessions オブジェクトがあります。
HasMany(s => s.Enrollments);
HasRequired(s => s.Course).WithMany(c => c.Sessions).HasForeignKey(s => s.CourseId);
HasRequired(s => s.Teacher).WithMany(t => t.Sessions).HasForeignKey(s => s.TeacherId);
HasRequired(s => s.Term).WithMany(t => t.Sessions).HasForeignKey(s => s.TermId);
次のデータをシードしようとしています (AddOrUpdate の前に、thisCourse、currentTerm、smith オブジェクトのそれぞれに対してクエリを実行します)
context.Sessions.AddOrUpdate(s => new { s.CourseId, s.TermId, s.TeacherId },
new Session { Course = thisCourse, Term = currentTerm, Teacher = smith}
);
これにより、常に次の追加が発生します。
<new id> 1 1 1
一致する条件が失敗する理由がわかりません。これは適切に更新されていませんが、常に追加されています。