Advertisement
Guest User

Seed

a guest
Dec 20th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. public class ContextInitializerDropIfChanged : DropCreateDatabaseIfModelChanges<DomainDbContext>
  2.     {
  3.         protected override void Seed(DomainDbContext context)
  4.         {
  5.             base.Seed(context);
  6.  
  7.             List<Tour> tours = new List<Tour>
  8.             {
  9.                 new Tour
  10.                 {
  11.                     Price = 800.00m,
  12.                     StartedOn = DateTime.Now,
  13.                     EndedOn = DateTime.Now.AddMonths(1),
  14.                     Nights = 15
  15.                 },
  16.                 new Tour
  17.                 {
  18.                     Price = 650.00m,
  19.                     StartedOn = DateTime.Now.AddDays(10),
  20.                     EndedOn = DateTime.Now.AddMonths(2),
  21.                     Nights = 10
  22.                 },
  23.                 new Tour
  24.                 {
  25.                     Price = 350m,
  26.                     StartedOn = DateTime.Now.AddDays(5),
  27.                     EndedOn = DateTime.Now.AddDays(5),
  28.                     Nights = 5
  29.                 }
  30.             };
  31.  
  32.             List<Country> countries = new List<Country>
  33.             {
  34.                 new Country
  35.                 {
  36.                     Name = "Австрия"
  37.                 },
  38.                 new Country
  39.                 {
  40.                     Name = "Греция"
  41.                 },
  42.                 new Country
  43.                 {
  44.                     Name = "Турция"
  45.                 }
  46.             };            
  47.  
  48.             countries[0].Tours.Add(tours[0]);
  49.             countries[1].Tours.Add(tours[1]);
  50.             countries[2].Tours.Add(tours[2]);
  51.  
  52.             context.Countries.AddRange(countries);
  53.             context.SaveChanges();
  54.         }
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement