DLL Hell returns: EF Core (EF 7) scaffolding is broken by version mismatches.

I have spent the last several hours trying to use EF Core’s CLI scaffolding to reverse engineer (or scaffold) a small database into entity classes. First, it simply does not support scaffolding into a Core (or any) class library. Scaffolding is done with a command much like the following one.

dotnet ef dbcontext scaffold "data source=(local);initial catalog=HawkHead;integrated security=SSPI;multipleActiveResultSets=True" "Microsoft.EntityFrameworkCore.SqlServer" -c HhDbContext -o Data

Executing this on a class library results in an error that simply tells you that scaffolding to class libraries is not supported. One would think a quick and easy workaround would be to create a .NET Core Console Application, but then executing the above command results in any number of intractable exceptions. The most understandable one was that “Microsoft.EntityFrameworkCore.SqlServer.Design”: “1.0.1” was not compatible with “Microsoft.EntityFrameworkCore.Tools”: “1.0.0-preview2-final”. There is no higher version for “Tools”, despite MS bragging that Core was now RTM and will save the fucking world.

There is, however, a very simple workaround. Add an old fashioned .NET 4.6 Console Application to your solution, add EF 6 to it, use EF 6 to do your scaffolding, and because the entity classes are POCOs, you can just copy and paste them all into your new, trendy .NET Core class library, and they work just the same with EF Core (EF 7).