Anindya Chatterjee
Anindya Chatterjee

Reputation: 5964

Tool to generate DDL and POCO classes from EF Models

Is there any tool where I can draw Entity Framework models and it generates C# POCO classes and MSSQL DDL scripts from that?

Upvotes: 2

Views: 1112

Answers (2)

Mark Stafford - MSFT
Mark Stafford - MSFT

Reputation: 4336

J. Tihon's answer was perfectly correct, but there is another alternative - write your POCO classes manually and forego the designer. You will still get POCO classes and the ability to generate SQL (using the power tool or Migrations, which will eventually be included in the core EF Nuget package). Code FIrst is a methodology many developers prefer for new development, and if you still want a visual designer there's always the Visual Studio class designer to help you design your POCOs!

Upvotes: 0

J. Tihon
J. Tihon

Reputation: 4459

Yes, it's called Visual Studio, but to get the POCO classes rather than the complex EntityObjects you have to replace the code-generation strategy. This ability was added in VS 2010 and can be applied directly in the designer. YOu can get the POCO T4 template from the Visual Studio Extension gallery. It also contains a description on how to use it.

The DDL generation is also built-in to the designer (but can also be modified using T4 and Workflows).

Basically you have to:

  • Create your model in the Entity Framework designer (choose model-first approach)
  • Download the POCO template using Extension Manager ("ADO.NET C# POCO Entity Generator")
  • Apply the new template (right click the designer surface and choose "Add Code-Generation Item", which should allow you to select the POCO template
  • Right click the surface and choose "Generate database from model", which will create the correct DDL.

Upvotes: 4

Related Questions