Guest User

Untitled

a guest
Jul 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. public class Student
  2. {
  3. public int ID { get; set; }
  4.  
  5. public string NAME { get; set; }
  6.  
  7. public Course Course { get; set; }
  8. }
  9.  
  10. public class Course
  11. {
  12. public int ID { get; set; }
  13.  
  14. public string Name { get; set; }
  15. }
  16.  
  17. | ID | Course |
  18. ------------------------
  19. | 1 | Math |
  20. -----------------------
  21. | 2 | Physics |
  22. -----------------------
  23.  
  24. var student = new Student
  25. {
  26. Name = "ABC",
  27. Course = new Course { ID = 1, Name = "Math"}
  28. }
  29.  
  30. context.Students.add(student);
  31. context.SaveChanges()
  32.  
  33. context.Entry(student).State = EntityState.Added;
Add Comment
Please, Sign In to add comment