Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view database diagram in a Code First using localdb

I have a Code First project with Entity Framework 5.0.0 using localdb created in Visual Studio 2012 Ultimate. Although I can see my class relations in a Class Diagram, how to see a visual diagram of automatic generated database by EF ?

like image 779
Xaqron Avatar asked Nov 24 '12 20:11

Xaqron


People also ask

How do I display a SQL database diagram?

To open a database diagramDouble-click the name of the database diagram you want to open. Right-click the name of the database diagram you want to open, and then choose Design Database Diagram.

How do you use code first when an existing database schema?

To use code-first for an existing database, right click on your project in Visual Studio -> Add -> New Item.. Select ADO.NET Entity Data Model in the Add New Item dialog box and specify the model name (this will be a context class name) and click on Add. This will open the Entity Data Model wizard as shown below.

How do I view the database diagram in Visual Studio?

Database diagrams in xsd format can be opened in Visual Studio. Select main menu View > SQL Server Object Explorer to connect and view the desired SQL database objects. Connect using credentials to view database objects like Views, tables etc.

How do I convert code first to database first?

There is no way to convert your code-first classes into database-first classes. Creating the model from the database will create a whole new set of classes, regardless of the presence of your code-first classes. However, you might not want to delete your code-first classes right away.


2 Answers

Install Entity Framework Power Tools Beta 4, restart Visual Studio, right-click on the context in your solution view and you'll see a new 'Entity Framework' option in the context menu. Select 'View Entity Data Model' to see a beautiful visual database diagram in Visual Studio. Voilà!

Entity Framework 6 Power Tools: Link

like image 83
Ralph Lavelle Avatar answered Oct 02 '22 09:10

Ralph Lavelle


You can use Microsoft SQL Server Management Studio 2012 with localdb which supports Database Diagrams in they way you may be used to with other SQL Server database.

  1. Open Management Studio (should have been installed with Visual Studio)
  2. Connect to (localdb)\v11.0, with Windows Authentication
  3. Find the relevant database
  4. Expand Database Digrams, and install diagram support objects if you've not already
  5. Add the tables you need and you're done!

Source: This older but still relevant article: http://visualstudiomagazine.com/blogs/data-driver/2012/05/visual-studio-11-beta-easier-development-localdb.aspx

like image 44
TimS Avatar answered Oct 02 '22 07:10

TimS