Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.EntityFrameworkCore;
  6.  
  7. namespace StudentMeal.Models
  8. {
  9. public class ApplicationDbContext : DbContext
  10. {
  11. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  12. {
  13. optionsBuilder.UseSqlServer(
  14. @"Server=localhost;Database=StudentMeal;Trusted_Connection=true;");
  15. }
  16.  
  17. public DbSet<Meal> Meals { get; set; }
  18. public DbSet<Student> Students { get; set; }
  19. public DbSet<MealStudent> MealStudent { get; set; }
  20.  
  21. protected override void OnModelCreating(ModelBuilder modelBuilder)
  22. {
  23. modelBuilder.Entity<Student>().HasData(
  24. new Student()
  25. {Name = "Tom Schoonbeek", Email = "cleanstream@gmail.com", Phonenumber = "0123456789", Id = 1001},
  26. new Student()
  27. {Name = "Tom Smits", Email = "sniffmans@hotmail.com", Phonenumber = "9876543210", Id = 1002},
  28. new Student()
  29. {Name = "Sjoerd Schepers", Email = "SS@gmail.com", Phonenumber = "0621316473", Id = 1003});
  30.  
  31. modelBuilder.Entity<Meal>().HasData(
  32. new Meal
  33. {
  34. MaximumParticipants = 5,
  35. StudentId = 1001,
  36. Name = "Nasi Goreng",
  37. DayPrepared = new DateTime(2018, 9, 24, 18, 30, 0),
  38. Price = 10.00,
  39. Description = "Lekkere nasi mhmm",
  40. Id = 1001
  41. },
  42. new Meal()
  43. {
  44. MaximumParticipants = 5,
  45. StudentId = 1001,
  46. Name = "Spagetthi Bolognese",
  47. DayPrepared = new DateTime(2018, 9, 23, 18, 0, 0),
  48. Price = 8.50,
  49. Description = "Spagetthi",
  50. Id = 1002
  51. },
  52. new Meal()
  53. {
  54. MaximumParticipants = 5,
  55. StudentId = 1003,
  56. Name = "Pasta Carbonara",
  57. DayPrepared = new DateTime(2018, 9, 18, 17, 30, 0),
  58. Price = 2.50,
  59. Description = "Goedkoop en lekker",
  60. Id = 1003
  61. },
  62. new Meal()
  63. {
  64. MaximumParticipants = 5,
  65. StudentId = 1003,
  66. Name = "Aardappelen",
  67. DayPrepared = new DateTime(2018, 10, 25, 18, 00, 0),
  68. Price = 7.50,
  69. Description = "Van Hollandschen bodem",
  70. Id = 1004
  71. },
  72. new Meal()
  73. {
  74. MaximumParticipants = 5,
  75. StudentId = 1003,
  76. Name = "Pannenkoeken",
  77. DayPrepared = new DateTime(2018, 9, 15, 17, 30, 0),
  78. Price = 15.00,
  79. Description = "Lekkere pannenkoeken mhmm",
  80. Id = 1005
  81. }
  82. );
  83.  
  84. modelBuilder.Entity<MealStudent>().HasData(
  85. new MealStudent() {MealId = 1001, StudentId = 1002, Id = 1},
  86. new MealStudent() {MealId = 1001, StudentId = 1003, Id = 2},
  87. new MealStudent() {MealId = 1001, StudentId = 1001, Id = 3},
  88. new MealStudent() {MealId = 1002, StudentId = 1002, Id = 4},
  89. new MealStudent() {MealId = 1002, StudentId = 1003, Id = 5},
  90. new MealStudent() {MealId = 1002, StudentId = 1001, Id = 6},
  91. new MealStudent() {MealId = 1003, StudentId = 1002, Id = 7},
  92. new MealStudent() {MealId = 1003, StudentId = 1003, Id = 8},
  93. new MealStudent() {MealId = 1003, StudentId = 1001, Id = 9},
  94. new MealStudent() {MealId = 1005, StudentId = 1002, Id = 10},
  95. new MealStudent() {MealId = 1005, StudentId = 1003, Id = 11},
  96. new MealStudent() {MealId = 1005, StudentId = 1001, Id = 12},
  97. new MealStudent() {MealId = 1004, StudentId = 1002, Id = 13},
  98. new MealStudent() {MealId = 1004, StudentId = 1003, Id = 14});
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement