How do you create a visual model of EntityFramework code first

asp.net-mvc-4 c# entity-framework visual-studio visual-studio-2012

Question

If you look here you will notice that this guy is showing the Entity Model Diagrams, I would like to know how I can create an Entity Model Diagram from my EntityFramework code first classes.

It just gets frustrating trying to remember how everything links together just by looking at the code.

1
56
9/6/2013 12:38:24 PM

Accepted Answer

With the Entity Frameworks Power Tools installed you can right-click the context in your solution view, click on "Entity Framework", then select "View Entity Data Model".

This will create a neat diagram from your classes.

57
10/29/2018 1:43:56 PM

Popular Answer

An Entity Data Model Diagram is just a visual display of an EDMX file. In order to get such a diagram from a Code-First model you must create an EDMX file from it:

using System.Data.Entity.Infrastructure; // namespace for the EdmxWriter class

using (var ctx = new MyContext())
{
    using (var writer = new XmlTextWriter(@"c:\Model.edmx", Encoding.Default))
    {
        EdmxWriter.WriteEdmx(ctx, writer);
    }
}

This code creates a file Model.edmx that you can open in Visual Studio. It will display the model diagram. The EDMX file is a snapshot of your current Code-First model. When you change the model in code you must create a new EDMX file to reflect those changes in the diagram.



Related Questions





Related

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