Andre Pena
Andre Pena

Reputation: 59336

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

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:

My requirements:

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

Upvotes: 14

Views: 11805

Answers (2)

Shadi Alnamrouti
Shadi Alnamrouti

Reputation: 13248

I faced a similar case and I used Entities to DTO's generator. Although its purpose is to generate DTO's, however, I believe it can help someone in you case.

https://entitiestodtos.codeplex.com/

Upvotes: 0

amuz
amuz

Reputation: 364

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 xx.Context.tt and xx.tt 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 xx.tt files and dbcontext underneath your xx.Context.tt 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.

Upvotes: 1

Related Questions