I\'m trying to generate classes from a database (EntityFramework\'s database first approach).
For convenience, I\'m more or less walking along with this tutorial: ht
That worked for me.
I know this is old, but I spent a while trying to figure this out today, so I hope this helps someone.
I have a .Net Core project but I want to scaffold my files into a .Net Standard class library. DbContext-Scaffold
in the package manager console didn't work for me, but dotnet ef dbcontext scaffold
in a regular command prompt did.
I had to install these packages in my class library:
I had to have a .Net Core project set as the startup project in my solution and that project had to have a reference to my class library. I think that last part is what I was missing that kept me scratching my head for so long.
Finally, I cd'd into the class library from a command prompt and ran this:
dotnet ef dbcontext scaffold "<connection string>" Microsoft.EntityFrameworkCore.SqlServer -o <output folder> -s <relative path to my startup project>
I resolved it with right click on projects and "Unload Project" let only the EF project and run the commands
For me the issue was that I was trying to set it up in a new blank console project inside of the solution, which had no files, so the scaffolding tried to use this project as a startup project and couldn't find Main
. I fixed it by adding a new file with an empty main
I still had this problem even when I ensured that my project (which had EF Core installed) built correctly. It still failed with the "Build failed." message, which is visible when using the -Verbsose
flag.
I had to do this in my case:
-Project
in the package manager console command to point to my newly-created (and EF Core-provisioned) project. The last step was just for good measure, since there was only one project in my throw-away solution.It seems that this whole process requires an ASP.NET core project (or just a .NET Core project that isn't a class library) somewhere in the solution, presumably set as the solution startup project too.
I resolved it by stopping my server and then running it again.