Search code examples
entity-framework-coreasp.net-core-1.0.net-core-rc2

EntityFramework Core database scaffolding (.NET Core RC2)


I try to create an EntityFramework Core's model with an existing database (doc here : https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html) but I have an error.

When I try the Package Manager method, I have the error :

The term "MY_DATABASE_NAME" is not recognize as a valid command applet [...]

This is the command I execute :

Scaffold-DbContext "'MY_CONNECTION_STRING'" Microsoft.EntityFrameworkCore.SqlServer -outputDir MY_PATH -verbose

And when I try the Command Prompt method, I have this error :

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.EntityFrameworkCore.Tools.DispatchCommand.<>c__DisplayClass2_0.<Create>b__0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Object reference not set to an instance of an object.

Here the command I execute :

dotnet ef dbcontext scaffold "'MY_CONNECTION_STRING'" Microsoft.EntityFrameworkCore.SqlServer -outputDir MY_PATH -verbose

Before this question, I checked :

  1. If I have installed good packages (Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.Tools and Microsoft.EntityFrameworkCore.SqlServer.Design)
  2. If my project.json was correct (tools, ...)
  3. If my database was online, with good credentials

Solution

  • Succeed with command prompt :

    1. Replaced OutPutDir by o
    2. Removed verbose
    3. Removed single quotes

    Command :

    dotnet ef dbcontext scaffold "MY_CONNECTION_STRING" Microsoft.EntityFrameworkCore.SqlServer -o MY_ABSOLUTE_PATH