Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Windows Azure – SQL Azure – Using ADO.NET Entity Framework – Creating DataModel

Posted by Paul on November 13, 2011


Another good remarkable point regarding SQL Azure is the reuse of our existing skills with ADO.NET Entity Framework. As the SQL Azure connectivity using ADO.NET is possible, it opens the door for Entity Framework as well.

Abut ADO.NET Entity Framework

ADO.NET Entity Framework is an ORM (Object Relational Mapping) framework from Microsoft. It provides the flexibilities like tables to entities, relational mapping to properties, Data operations to encapsulated methods etc.

clip_image002

Surely it gives the advantages of:

  • Wrapping of database in Object Oriented Manner
  • More Manageability
  • More Flexibility
  • Less Development Time

But everything comes at the cost of learning. You can find more information here.

Creating Schema

Create a new Windows Azure project and add a new web role into it. After that right click on the project and use Add > New Item. In the appearing dialog choose the Data item from the left pane and ADO.NET Entity Data Model from the right pane.

clip_image004

Enter the names as MyModel as shown above. Click the Add button to continue to see the following screen.

clip_image006

In the above dialog choose the default option (Generate from database) and click the Next button to continue.

clip_image008

In the appearing dialog choose your existing connection from the drop down list and click Next to continue..

clip_image010

You will be prompted with the login dialog above. Enter your user name and password to continue. (The Save my password option saves the password to the connection string in config)

In the next dialog, select the tables as shown below and click Finish button.

clip_image012

This will generate the entity data model files in your project. You can see that the Employee table from previous example is populated in the tables and it generates the Employee class as shown below.

clip_image014

Note: If your database does not contain the above table, you may need to create the table and repeat the operations.

Summary

In this article we have explored the scope of using ADO.NET Entity Framework on SQL Azure. The possibilities give us more flexibility, control and reuse of our existing ORM skills. The source code attached contains the Entity Data Model code. You need to change the database name, user name and password in the configuration file.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s