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
donet ef tools: DbContext configuration in WebApp project with DbContext in a class library no longer works in RC2 #5460
Comments
I followed this workaround: https://docs.efproject.net/en/latest/cli/dotnet.html#dotnet-cli-issues Now the problem is that the class library has no clue about the connection details as those details are in the configuration section of the web project.
I am stuck! |
I struggled a bit with the same problem, my ef code is in a class library. I converted it to an app as mentioned in the workaround notes but also added a Program.cs and Startup.cs and appsettings.json and I was able to run the migration from the command line. It may help you to browse my project here https://github.com/joeaudette/cloudscribe/tree/master/src/cloudscribe.Core.Storage.EF the notes about upgrading from rc1 to rc2 were also helpful https://docs.efproject.net/en/latest/miscellaneous/rc1-rc2-upgrade.html |
Thanks @joeaudette. Basically you created another Web App with just the information the migrations tool uses. Very dirty!! Hope they fix this soon. |
@joeaudette how will the migrations be performed in production? Does the WebApp know which code to run to apply the latest migrations? |
@Villason I'm only generating the migrations from the command line, then they are compiled into the code. Running the migrations happens from the startup of my web app invoking a method here where I am also seeding some data you can see my web app startup here though I have not yet tested with multiple migrations, its working fine for me so far with the one initial migration |
This is probably a duplicate of this issue: #5320. It's a known limitation of .NET Core CLI preview 1 and unfortunately something we cannot work around. We depend on them to provide support for running "dotnet ef" on class library projects. @joeaudette glad you got the workaround we shared to work. You could also use multi-targeting so that you can use dotnet-ef on a class library. cref http://dotnet.github.io/docs/core-concepts/libraries/libraries-with-cli.html#how-to-multitarget |
Agreed that this is dupe of #5320 - at the moment we only support everything being in a single project that the command is being executed on. |
I was able to get this work a different way. My setup is as described above. A Web app which has the connection string configuration and sets up EF, all Context, model, Entity Framework stuff in a class library. For RC1 the Migrations were stored in the class library too. For RC1 I would call commands like this:
When I tried to do this in RC2 I got the above errors. but it suggested:
So, I simply did what it said.
When I tried to use the
|
@kjbetz Thanks Mannnnn |
My migrations scripts no longer work:
Error:
Unrecognized option '-p'
My setup is as follows:
MySolution.Web contains the DbContext configuration details like the connection strings.
MySolution.Data.EntityFramework contains my EntityFramework implementation of my data access interfaces. It contains the DbContext and the Migrations in RC1.
What's the proper way to do this now? It appears I can no longer separate the DbContext from its configuration!
The text was updated successfully, but these errors were encountered: