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.


Discover more from Dhananjay Kumar

Subscribe to get the latest posts sent to your email.

Published by Dhananjay Kumar

Dhananjay Kumar is founder of NomadCoder and ng-India

One thought on “SQL Azure with LINQ

Leave a comment

Discover more from Dhananjay Kumar

Subscribe now to keep reading and get access to the full archive.

Continue reading