日期:2014-05-17 浏览次数:20426 次
public class Course
{
public int Id { get; set; }
public string Name { get; set; }
public List<Student> Students { get; set; }
}
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public List<Course> Courses { get; set; }
}
using (var context = new BreakAwayContext())
{
var student = new Student()
{
Name = "Ray",
Courses = new List<Course>() {
new Course() { Name = "Math" },
new Course() { Name = "English" }
}
};
context.Students.Add(student);
context.SaveChanges();
Assert.AreEqual(1, context.Students.Where(x => x.Name == "Ray").Count());
}
//Update
using (var context = new BreakAwayContext())
{
var student = (from d in context.Students.Include(x