entity framework code first many to many add/update/delete/select
entity framework code first many to many add/update/delete/select求实例讲解,主要是删除,不要什么级联删除,要代码实现(include)。最好是三个表以上。
select d).Single();
student.Courses.Add(new Course() { Name = "Computer Science"} );
context.SaveChanges();
//Assert.AreEqual(0, context.Husbands.Where(x => x.Name == "A").Count());
Assert.AreEqual(3, context.Courses.Count());
}
//Delete
using (var context = new BreakAwayContext())
{
var student = (from s in context.Students
where s.Name == "Ray"
select s).Single();
context.Students.Remove(student);
context.SaveChanges();
Assert.AreEqual(0, context.Students.Where(x => x.Name == "Ray").Count());
}