Connecting to SQL Azure with Telerik OpenAccess

Posted by: the telerik blogs, on 02 Nov 2009 | View original | Bookmarked: 0 time(s)

With the official release of SQL Azure less than three weeks away, we are starting to see mainstream vendor support for SQL Azure. Teleriks OpenAccess ORM is no exception. With the Q3 release of OpenAccess next week, OpenAccess will have full support for SQL Azure, going further than the basic support available today that I demonstrated on my blog last month. Full wizard support, forward and reverse mapping, and of course data services support via the Telerik Data Services Wizard. Lets take a look at the basics here.

Getting Started

To get up and running and show the mapping and LINQ support, I will open Visual Studio 2008 (or 2010) and create a simple Console Application named OpenAccess.Azure.Demo. The first step is to enable the project to use OpenAccess via the Enable Project Wizard. As part of the wizard you need to specify which database you are going to connect to. OpenAccess gives you many choices besides Microsoft SQL Server, and one of the native choices is Microsoft SQL Azure. After you select SQL Azure, you will need to provide your credentials (dont forget to put the tcp: in front of your server name.)

image

After you connect and finish the wizard, it is time to do some mapping.

Mapping Database Objects

To map some database objects to persistent classes, choose the Reverse Mapping wizard. This will bring up the Reverse Mapping dialog where you can select which tables, views, and stored procedures you want to map. In this case I will just select all of the defaults and map all of Northwind (remember I migrated Northwind up to SQL Azure.) Now it is time to build a simple application.

image

Working with SQL Azure Data

Lets write a LINQ statement to fetch all of the customers from one country and print it out to the console window. First tings first, you have to put in a using statement for OpenAccess:

using Telerik.OpenAccess;

Next we will create our LINQ statement. The LINQ statement will work like any LINQ statement in OpenAccess, there is nothing special for SQL Azure, this LINQ statement would work against SQL Server, MySQL, or Oracle.

 1: static void Main(string[]
args)
 2: {
 3:  //data context
 4:  IObjectScope dat = ObjectScopeProvider1.GetNewObjectScope();
 5:  //LINQ Statement
 6:  var result = from c in dat.Extent<Customer>()
 7:  where c.Country
== "Germany"
 8:  select c;
 9:  //Print out the
company name
 10:  foreach (var cust in result)
 11:  {
 12:  Console.WriteLine("Company
Name: " + cust.CompanyName);
 13:  }
 14:  //keep the console window open
 15:  Console.Read();
 16: }

The LINQ statement uses the data context, or IObjectScope in line 4, has a simple LINQ statement on lines 6-8 to filter by the customers in Germany and then iterates those customers and prints them out to the console window in lines 10-13. The result is shown here:

image

Pretty basic application, however, you can see that Telerik OpenAccess has full support for SQL Azure. Next week I will show a more complete example.

Enjoy!

Technorati Tags: SQL Azure,Telerik

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: SQL | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 1202 | Hits: 42

Similar Posts

  • Using WCF with SQL Azure and Telerik OpenAccess more
  • How to display data from different tables using one data source more
  • Telerik OpenAccess WCF Wizard October CTP more
  • Binding Hierarchical RadGrid for ASP.NET Ajax with Telerik OpenAccess ORM more
  • Binding Hierarchical RadGrid with Telerik OpenAccess ORM more
  • Create a SQL Azure CRUD Application with Telerik OpenAccess and the WCF Wizard more
  • Using the Telerik OpenAccess WCF Wizard with Multiple Versions of OpenAccess more
  • RadScheduler for Silverlight learning series, part 3: Add, Edit, and Delete Appointments more
  • PDC 2009 Sessions Posted more
  • Tracing the SQL Statements Generated by Telerik OpenAccess ORM more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD