Hi I'm using the Code first method within Entity Framework using Visual Studio 2012 Could someone tell me if I should add context.SaveChanges();
at the end of my Seed method within the configuration.cs file in order to successfully update my tables? I can make structural changes using update-database -verbose in the console, but this doesn't update my data.
edit: you do in fact not need to call SaveChanges
. Thus, this must mean that after the Seed
method has been called, a call to SaveChanges
is automatically made. However, it is perhaps useful to note that you can call SaveChanges()
within the Seed
method if you want, which can be useful when dealing with foreign key relations.
Initializers that provide Seed
usually look like this inside...
// ...do something - prepare Db, Create etc.
Seed(context); // you override that
context.SaveChanges();
...just to clarify further.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.