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

C#Sql Serverasp.net CoreEntity Framework-Core

C# Problem Overview


I've been playing around with Entity Framework 7 and ASP.NET 5 for a new project I'm working on, but I've hit a roadblock. The team I'm working on uses a DBA-first approach to development; i.e. the database is designed by DBA's and then the developers alter the code to compensate for the model changes.

Using EF6, this works well, since we can just update the code using the EDMX designer's "update" functionality. One click, we get the new classes, and we're done. However, in EF7, everything is different. There's no more designer, and we're supposed to use Code-First, which according to some blog postings out there by the EF team, should also support "Database-First" code generation.

However, I'm unable to figure out how to do this with the Visual Studio 2015 CTP6 in an ASP.NET 5 application. Is the tooling support there yet, or am I out of luck? And is it even coming at all?

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

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

Solution 3 - C#

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.

Solution 4 - C#

@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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRon PentonView Question on Stackoverflow
Solution 1 - C#ErikEJView Answer on Stackoverflow
Solution 2 - C#BiLaLView Answer on Stackoverflow
Solution 3 - C#Simon_WeaverView Answer on Stackoverflow
Solution 4 - C#vivek nunaView Answer on Stackoverflow