1- using System . Data . Entity ;
21using System . Data . Entity . Migrations ;
32using webapi . Models ;
3+ using Microsoft . EntityFrameworkCore ;
44
55namespace webapi . Data
66{
77 public class webapiInitializer : CreateDatabaseIfNotExists < webapiContext >
88 {
99 protected override void Seed ( webapiContext context )
1010 {
11- context . Authors . AddOrUpdate (
12- x => x . Id ,
13- new Author ( ) { Id = 1 , Name = "Jane Austen" } ,
14- new Author ( ) { Id = 2 , Name = "Charles Dickens" } ,
15- new Author ( ) { Id = 3 , Name = "Miguel de Cervantes" }
16- ) ;
17-
18- context . Books . AddOrUpdate ( x => x . Id ,
19- new Book ( )
20- {
21- Id = 1 ,
22- Title = "Pride and Prejudice" ,
23- Year = 1813 ,
24- AuthorId = 1 ,
25- Price = 9.99M ,
26- Genre = "Comedy of manners"
27- } ,
28- new Book ( )
29- {
30- Id = 2 ,
31- Title = "Northanger Abbey" ,
32- Year = 1817 ,
33- AuthorId = 1 ,
34- Price = 12.95M ,
35- Genre = "Gothic parody"
36- } ,
37- new Book ( )
38- {
39- Id = 3 ,
40- Title = "David Copperfield" ,
41- Year = 1850 ,
42- AuthorId = 2 ,
43- Price = 15 ,
44- Genre = "Bildungsroman"
45- } ,
46- new Book ( )
47- {
48- Id = 4 ,
49- Title = "Don Quixote" ,
50- Year = 1617 ,
51- AuthorId = 3 ,
52- Price = 8.95M ,
53- Genre = "Picaresque"
54- }
55- ) ;
56-
11+ context . Authors . AddOrUpdate ( x => x . Id , new Author ( )
12+ { Id = 1 , Name = "Jane Austen" } , new Author ( )
13+ { Id = 2 , Name = "Charles Dickens" } , new Author ( )
14+ { Id = 3 , Name = "Miguel de Cervantes" } ) ;
15+ context . Books . AddOrUpdate ( x => x . Id , new Book ( )
16+ { Id = 1 , Title = "Pride and Prejudice" , Year = 1813 , AuthorId = 1 , Price = 9.99M , Genre = "Comedy of manners" } , new Book ( )
17+ { Id = 2 , Title = "Northanger Abbey" , Year = 1817 , AuthorId = 1 , Price = 12.95M , Genre = "Gothic parody" } , new Book ( )
18+ { Id = 3 , Title = "David Copperfield" , Year = 1850 , AuthorId = 2 , Price = 15 , Genre = "Bildungsroman" } , new Book ( )
19+ { Id = 4 , Title = "Don Quixote" , Year = 1617 , AuthorId = 3 , Price = 8.95M , Genre = "Picaresque" } ) ;
5720 context . SaveChanges ( ) ;
5821 base . Seed ( context ) ;
5922 }
6023 }
61- }
24+ }
0 commit comments