Step 1: Create the solution and Entity Framework Data Model

If you haven’t already, read the article this example is based on or start at the beginning of this example.

In Visual Studio 2010, create a blank solution named Customer Success Stories:

SNAGHTML16c1ba2

Write click on the solution and Add | New Project:

image

Create a Class Library project named CSSModel:

SNAGHTML17296e9

Delete the class file and then Add | New Item:

image

Choose ADO.NET Entity Data Model and name it CSSModel:

SNAGHTML175e095

Choose Empty Model and Finish:

SNAGHTML177e6dc

Drag a couple of entities from the toolbox onto the design surface. Rename one Company and give it Name and Country properties. Name the other Story and give it Headline and Detail properties:

SNAGHTML17aa0e7

For this project, DON’T use the toolbar to add the association. Instead, right-click on Company and Add | Association (make sure “Add foreign key …” is checked):

SNAGHTML17d284f

Your model should look like this:

image

Right-click on the design surface to Generate Database from Model:

image

If you haven’t connected to your SQL Azure database yet, you’ll need to create a new connection:

SNAGHTML18b433e

Enter your fully qualified DNS name (found on the right side of the database page in the Windows Azure portal). Then choose SQL Server Authentication with the user name and password you created. Click the Test Connection button to verify that your connection is working, and then you can select the database name:

SNAGHTML1910333

On the next screen, click “Yes …” to include sensitive data in the connection string (you have to put it somewhere – this will put it in a .config file, which is a good place):

SNAGHTML1949c56

Click Finish to generate the DDL and open CSSModel.edmx.sql. On the SQL toolbar, click the Connect button:

image

Once again, enter your fully qualified DNS name for your database, along with your SQL Server Authentication credentials (the first time, it’s remembered in App.Config – this time, it’s remembered by Visual Studio itself):

SNAGHTML19980ab

If you try to execute the SQL at this point, it will fail, because the “Master” database is selected and SQL Azure does not understand the “Use” statement at this time. So select CSSDB from the database dropdown and then click execute:

image

Now you have a SQL Azure database. You can manipulate it by clicking Manage on the database toolbar in the Windows Azure account portal:

image

Continue to step 2.

Leave a Reply

Your email address will not be published. Required fields are marked *