SIGN UP MEMBER LOGIN:    
ARTICLE

Remote and Local execution of Query in LINQ

Posted by Dhananjay Kumar Articles | LINQ with C# January 07, 2011
Remote execution is being default and same as majority of the query we write in LINQ.
Reader Level:

Remote Execution of Query

  1. This query executes on the server.
  2. Remote execution of query is default in LINQ.
  3. In Remote execution advantage of Databases index can be taken.
  4. Remote execution allows us to take the advantage of Database server engine.
  5. 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

1.gif


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.

    2.gif

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

3.gif

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor