Using multiple diagrams per model in Entity Framework 5.0

I have downloaded .Net framework 4.5 and Visual Studio 2012 since it was released to MSDN subscribers on the 15th of August.For people that do not know about that yet please have a look at Jason Zander's excellent blog post .

Since then I have been investigating the many new features that have been introduced in this release.In this post I will be looking into the new support for multiple diagrams that EF Designer has out of the box.

In order to follow along this post you must have Visual Studio 2012 and .Net Framework 4.5 installed in your machine.Download and install VS 2012 using this link.

My machine runs on Windows 8 and Visual Studio 2012 works just fine.

I have also installed in my machine SQL Server 2012 developer edition. I have also downloaded and installed AdventureWorksLT2012 database.You can download this database from the codeplex website.  

Before I start showcasing the demo I want to say that I strongly believe that Entity Framework is maturing really fast and now at version 5.0 can be used as your data access layer in all your .Net projects.

I have posted extensively about Entity Framework in my blog.Please find all the EF related posts here.

In this demo I will show you how to split an entity model into multiple diagrams using the new enhanced EF designer. We will not build an application in this demo.

Sometimes our model can become too large to edit or view.In earlier versions we could only have one diagram per EDMX file.In EF 5.0 we can split the model into more diagrams.

1) Launch VS 2012. Express edition will work fine.

2) Create a New Project. From the available templates choose a Web Forms application 

3) Add a new item in your project, an ADO.Net Entity Data Model. I have named it AdventureWorksLT.edmx.Then we will create the model from the database and click Next.Create a new connection by specifying the SQL Server instance and the database name and click OK.Then click Next in the wizard.In the next screen of the wizard select all the tables from the database and hit Finish.

4) It will take a while for our .edmx diagram to be created. When I select an Entity (e.g Customer) from my diagram and right click on it,a new option appears "Move to new Diagram".Make sure you have the Model Browser window open.

Have a look at the picture below

 

5) When we do that a new diagram is created and our new Entity is moved there.

Have a look at the picture below

 

 6) We can also right-click and include the related entities. Have a look at the picture below.

 

7) When we do that the related entities are copied to the new diagram.

Have a look at the picture below 

 

8) Now we can cut (CTRL+X) the entities from Diagram2 and paste them back to Diagram1.

9) Finally another great enhancement of the EF 5.0 designer is that you can change colors in the various entities that make up the model.

Select the entities you want to change color, then in the Properties window choose the color of your choice. Have a look at the picture below.

 

To recap we have demonstrated how to split your entity model in multiple diagrams which comes handy in EF models that have a large number of entities in them

Hope it helps!!!!

2 Comments

Comments have been disabled for this content.