How to generate Entity Framework 6.x POCO classes with mappings from an EDMX file?

.net c# entity-framework


I'm in the process of converting an extensive EDMX model into POCO classes. I need to go from a Database First approach (EDMX with ObjectContext) to a pure Model First approach (DbContext with no EDMX file). I need to use the latest Entity Framework stable version: 6.1.1.

I've tested some approaches:

  • Adding a the EF 6.x DbContext Generator code generation item by right-clicking the blank space in EDMX designer. This works fine, but it doesn't add any mappings. With this approach I have to still use the EDMX file. It's not full Code First.
  • Using the EF 5.x DbContext Fluent Generator for C#. This triggers an exception in design time. I'm not being able to use it. I don't know if that's because my VS Entity Framework tools are already updated to 6.x. Using the alternative TT in the comments, that suggests that it would work with EF 6.0 also doesn't help.
  • Using the EntityFramework Reverse POCO Generator. This is the worst because it won't consider any of my classes and navigation properties renames.
  • Using the Entity Framework Power Tools Beta 4. Again, it only supports generating from the database, not from the EDMX file.

My requirements:

  • I need the input to be the EDMX file, not the database.
  • I need the output to be a full Code First approach with Fluent mappings.
  • I need all my navigation property names defined in the EDMX to be considered because otherwise it would break a large codebase, even more then migrating from ObjectContext to DbContext will break.

What do you think would be a good option for me to go?

12/10/2014 8:43:15 PM

Popular Answer

Well i don't think there is an easy one click solution to this.

Underneath you edmx files. You have two more files available besides the xx.Designer.cs and xx.edmx.diagram.. called and where xx is the name of your edmx model.

These are t4 templates which genrate your dbcontext and poco objects. All your poco objects would be created underneath your files and dbcontext underneath your files.

You now have to moves these into separate files. This is much easier if you are using EF6. and the file generated are already using DbContext and not ObjectContext.

12/11/2014 12:27:26 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow