-
Notifications
You must be signed in to change notification settings - Fork 10.3k
How to correctly seed a DbContext using ASP.NET Core 2.0? #2188
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
Comments
@bricelam where is the guidance for moving this to Main? |
I'm not sure where/if it got documented... |
@divega might know. |
I wrote a blog post based on information I found in issues here, can't remember the specific issue where I saw it but my understanding is seeding and running migrations should now be done in Program.cs not in startup. like this:
|
just found the issue with the guidance forgot I linked it from my post |
This is the issue I created asking for this to be covered in the 1.x-to-2.x migration documentation: @joeaudette feel free to up-vote. |
This issue is being closed because it has not been updated in 3 months. We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate. |
Uh oh!
There was an error while loading. Please reload this page.
Hello, dear friends in ASP.NET!
I haven't found any information and this is a so common task that I'm almost forced to ask you to, please, give a helping hand to people like me, that are trying to get into the ASP.NET Core ship.
What I'm trying to do is to seed my database with sample data. I haven't found a nice place to perform this startup task. However, some people says the
Startup.Configure
can be a right place.However, after following the advice, I have faced some problems with the resolution of the DbContext.
This is my Startup class:
As usual, I register my DbContext in ConfigureServices. But after that, in the Startup.Configure method, when I try to resolve it using GetRequiredService, it throws with this message:
I've also posted this as a question in StackOverflow: https://stackoverflow.com/questions/46063945/cannot-resolve-dbcontext-in-asp-net-core-2-0
Big thanks for the help, in advance.
The text was updated successfully, but these errors were encountered: