Telerik blogs

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 Azure.

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!


About the Author

Steve Forte

 sits on the board of several start-ups including Triton Works. Stephen is also the Microsoft Regional Director for the NY Metro region and speaks regularly at industry conferences around the world. He has written several books on application and database development including Programming SQL Server 2008 (MS Press).

Comments

Comments are disabled in preview mode.