Remote and Local execution of Query in LINQ

No.of Views1644
Bookmarked0 times
Downloads 
Votes0
By  Dhananjay Kumar   On  07 Jan 2011 07:01:15
Tag : LINQ , General
In this article we will focus LINQ Remote and Local exaction such as This query executes on the server, Remote execution of query is default in LINQ, In Remote execution advantage of Databases index can be taken, Remote execution allows us to take the advantage of Database server engine, Remote execution allows us to only select particular rows from the table. This is very useful when we do have large amount of data in the server.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In this article we will focus LINQ Remote and Local exaction such as This query executes on the server, Remote execution of query is default in LINQ, In Remote execution advantage of Databases index can be taken, Remote execution allows us to take the advantage of Database server engine, Remote execution allows us to only select particular rows from the table. This is very useful when we do have large amount of data in the server.

Remote execution is being default and same as majority of the query we write in LINQ.

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq ; 
 
namespace ConsoleApplication5
  {
    class Program
        {
            static void Main(string[] args)
                {
                    DataClasses1DataContext context = new DataClasses1DataContext();                   
                    var result = from r in context.Persons orderby r.FirstName select r;
                    foreach (var r in result)
                    {
                        Console.WriteLine(r.FirstName + " " + r.LastName);
                    }
                    Console.ReadKey(true);
                }
        }
 }

 Output

Image Loading

Local Execution of Query

1.    In local execution of query they get executed in local cache. 
2.    The biggest advantage is who data loaded locally can be serialized.
3.    For each time to get Data there is no need to go back to server.
4.    Using Load of local execution related entities can be fetched together.
5.    Load() method is used to execute query locally.
 

Image Loading

In above query Person table and StudentGrades table are related to each other.

Program.cs

using System;
using System.Linq;
using System.Data.Linq;
namespace ConsoleApplication5
  {
    class Program
        {
            static void Main(string[] args)
                {
                    DataClasses1DataContext context = new DataClasses1DataContext();                  
 
                    Person  p = context.Persons .Single(res => res.PersonID   == 9);                 
                    p.StudentGrades.Load();
                    foreach (var r in p.StudentGrades)
                    {
                        Console.WriteLine(r.Grade);
                    }
                    Console.ReadKey(true);
                    
                }
        }
}

Output 

Image Loading

That's all. hopes help and happy coding.

 
Sign Up to vote for this article
 
About Author
 
Dhananjay Kumar
Occupation-Software Engineer
Company-Infosys Technolgies,Pune
Member Type-Gold
Location-India
Joined date-20 Jul 2009
Home Page-http://dhananjaykumar.net/
Blog Page-http://dhananjaykumar.net/
Dhananjay Kumar is Microsoft MVP on connected system. He blogs at http://dhananjaykumar.net/ . You can follow him http://twitter.com/debugmode_/ and reach him at dhananjay.25july@gmail.com
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top