Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an Entity Framework 7 Database-First POCO Generator?

In the latest bits it is possible to use the dnx command prompt and PowerShell commands to do this, yes

Scaffold-DbContext '<connectionString>' EntityFramework.MicrosoftSqlServer

or

dnx ef dbcontext scaffold "<connectionString>"  EntityFramework.MicrosoftSqlServer

or (from EF Core RC2)

dotnet ef dbcontext scaffold "<connectionString>"  Microsoft.EntityFrameworkCore.SqlServer

You must install the Microsoft.EntityFrameworkCore.Tools package for the command to work.


This can be done using NuGet package manager console or command prompt. I tried with command prompt. After navigating to the project folder in command prompt, I used a similar command:

dnx ef dbcontext scaffold "Data Source=myServerName; Initial Catalog=myDatabaseName; Integrated Security=True" EntityFramework.SqlServer

I got errors about the missing packages:

EntityFramework.Commands

EntityFramework.SqlServer.Design

followed by this command before proceeding:

dnu restore

The actual package(s) required may vary based on the mentioned framework(s) in you project.json file.

If you are unable to execute the dnx or other related commands at the command prompt, follow THIS link which has been mentioned in comments of another answer.

P.S. : Here is the current command list [at the time of writing, last updated Aug 21]:

ASP.NET - EntityFramework Wiki -- NuGet/DNX Commands


Here are the updated parameters for RC2 of .NET Core (May 2016)

dotnet ef dbcontext scaffold -c RRStoreContext -o Model 
"Data Source=(local);Initial Catalog=DBNAME;Integrated Security=True"     
Microsoft.EntityFrameworkCore.SqlServer --force

Note that Microsoft.EntityFrameworkCore.SqlServer is the new name for the package that needs to be used in the command. I've added the force parameter to overwrite existing files. The 'o' parameter is output directory name. And it's now dotnet instead of dnx.

As of the current release the dependencies you need in your project.json are

"dependencies": {
    "Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.Tools": {
      "type": "build",
      "version": "1.0.0-preview1-final"
    }
  },

Note: Type of 'build' means that anything referencing your assembly won't take this DLL as a dependency since it's only needed for tooling.


@ErikEJ has developed a very useful tool for this. Which generates POCO classes just by doing right click on the project and provide you SQL server instance.You can download it from here and steps are clearly mentioned here.