SQL Azure with LINQ

LINQ could be used with SQL Azure in the same way it is used with SQL Server. We are going to use School database again. So to see how we can use SQL Azure with LINQ

1. Create a console Appli8cation. For purpose of this walkthrough , I am creating Console app. You can use in same way in other managed application.

2. Right click on console application project. Select add new item and choose LINQ to SQL Class form Data tab.

clip_image002

3. Choose the option Server explorer and add a new connection. In Add new connection windows provide information for SQL Azure.

clip_image003

4. Now we need to write usual LINQ query to do CRUD operation against database in SQL Azure. Here I am fetching all the records from Person class

Program.cs


using System;
using System.Linq;

namespace LINQSQLAzure
{
 class Program
 {
 static void Main(string[] args)
 {
 DataClasses1DataContext context = new DataClasses1DataContext();
 var result = from r in context.Persons select r;
 foreach (var r in result)
 {
 Console.WriteLine(r.LastName + " " + r.FirstName);
 }
 Console.ReadKey(true);
 }
 }
}

Expected output,

clip_image005

In this post , I explained LINQ with SQL Azure.

One response to “SQL Azure with LINQ”

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 )

Facebook photo

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

Connecting to %s

Create a website or blog at WordPress.com