New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I perform database initialization/seeding with EF7? #3042
Comments
Nothing yet, but we will have content in our docs. You would put initialization logic in your app startup - Main, Startup.cs, TextFixture, etc. depending on the application type. If you are using migrations there is Seed data would just go inline with your startup code too, here is an example in an ASP.NET 5 application: |
That's just awesome. Thanks for sharing the links @rowanmiller! |
@rowanmiller, @bricelam I can use 'Sql' operation from MigrationBuilder, but it is not very useful. I think it will be more useful if MigrationBuilder will support operations like Insert/Update/Delete or even InsertOrUpdate. Take a look at ecm7migrator object model as example. It is not the best, but good to show what I mean. |
@resnyanskiy having a proper hook for seeding is already tracked by #629 If you want to see an example of how to do it in the meantime in an ASP.NET 5 app, here is a pattern you can use:
For other applications you would follow the same pattern of doing it on app startup... but it's easier since you don't need to worry about DI. |
@rowanmiller |
I have posted a solution on my blog for seeding data in EF7. Feel free to check it out and use it if you find it useful. http://coderhints.com/ef7-seed-user/ |
Hi Rowan, I am starting out with MVC and EF7 and need help. i came across your UnicornStore sample app and would like to know whether you have a guide to how to set it up to run. i tried everything and nothing. your help will be appreciated. Thanks (gartycx@gmail.com) |
Hi there, I myself am not Rowan, and I do not have a guide to setup and run MVC/EF7. However, if you want to see some sample code on how to seed with EF7, you may find my blog posting helpful. http://coderhints.com/ef7-seed-user/ Regards, Jeff From: gclaasen Hi Rowan, I am starting out with MVC and EF7 and need help. i came across your UnicornStore sample app and would like to know whether you have a guide to how to set it up to run. i tried everything and nothing. your help will be appreciated. Thanks (gartycx@gmail.com) — |
@gclaasen feel free to open a new issue with details of the error you are seeing etc. |
Hi,
I've created a code-first model with EF7 beta7 in an ASP.NET 5 MVC 6 project.
Now I want to have some users registered and some other sample data initialized when the application runs, how is this done the proper way?
I used to do this with
DbInitializer
, but I believe this technique has been retired now.The whole subject of initialization is blurry to me.
When I create a new project and expand the data model, am I supposed to erase the Migrations folder and add a new migration all anew?
Is there a tutorial that explains how migrations, snapshots, and database initialization work in EF7?
The text was updated successfully, but these errors were encountered: