“Build failed” on Database First Scaffold-DbContext

后端 未结 18 1729
醉梦人生
醉梦人生 2020-12-24 04:31

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

18条回答
  •  被撕碎了的回忆
    2020-12-24 04:48

    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:

    • Microsoft.EntityFrameworkCore.SqlServer
    • Microsoft.EntityFrameworkCore.Design
    • Microsoft.EntityFrameworkCore.Tools

    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 "" Microsoft.EntityFrameworkCore.SqlServer -o  -s 
    

提交回复
热议问题