# Thursday, 01 July 2010

With the Q1 release of Telerik OpenAccess ORM, Telerik released a brand new LINQ Implementation and supporting Visual Entity Designer. I have shown in this blog how to connect to SQL Server, MySQL, and how to use the new LINQ with RIA Services. Today I will show you how to connect to SQL Azrue.

To get started, we have to create a new Telerik Domain Model in the server (ASP.NET) project. We’ll create a new Domain Model by right clicking on the server project and selecting “Add” and choosing the Telerik Domain Model from the menu.

In the dialog presented by OpenAccess select the database you want to connect to, for this project choose Microsoft SQL Azure. You also have to manually put in the connection string to SQL Azure in the format of:

Server=tcp:yourSQLAzureDatabaseServer;Database=YourDatabaseName;USER=YourUserID, Password=YourPassword;

clip_image001

Next you have to map your tables to entities. The easiest thing to do is just map all of your tables by selecting the checkbox next to “Tables” in the Choose Database Items dialog and pressing the Finish button.

clip_image002

Visual Studio adds a new Telerik Domain Model to your project.

clip_image003

Now you are free to use the LINQ implementation to build your application. For simplicity, I will drag a gridView control onto the form and then use LINQ to bind all the customers in Germany. The code is here:

 

   1:  protected void Page_Load(object sender, EventArgs e)
   2:  {
   3:      if (IsPostBack==false)
   4:      {
   5:       //data context
   6:       NorthwindEntityDiagrams dat = new NorthwindEntityDiagrams();
   7:       //LINQ Statement
   8:       var result = from c in dat.Customers
   9:                           where c.Country == "Germany"
  10:                           orderby c.CustomerID
  11:                           select c;
  12:      //Databind to the ASP.NET GridView
  13:      GridView1.DataSource = result;
  14:      GridView1.DataBind();
  15:      }
  16:  }
  17:   

The results are show here.

clip_image005

Enjoy!

Comments are closed.