Tuesday, August 9, 2011

Generating a table design from your code

A while back, I had take some code home to work on, but forgot to copy the database design. It turns out that it isn't the end of the world when that happens. If you're using the Entity Framework and have generated an .edmx file in your solution, then it's fairly simple to regenerate your database on the fly.

Step 1: Double click and open your .edmx file.

Step 2: Right click inside the new opened database design and click the Generate Database from Model... selection.

Step 3: Make sure that everything appears to be in order and click the Finish button. It should ask you where you would like to save the file. You can select just about anywhere, just as long as you know you can find it. You'll need to it to generate your database in SQL Server.

Step 4: Copy the generated SQL Server Express, click the New Query button.

Step 5:  Copy your code into the query window. 
Step 6: After you've verified that everything is correct, click Execute.

The above assumes that you already know how to create the database, so configuring everything shouldn't be a problem. As always, Microsoft keeps things fairly friendly for the developer. 


No comments:

Post a Comment