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.Linq;
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);
 
 
                }
        }
}
 

clip_image002

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.

clip_image004

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

clip_image006

Advertisements

One thought on “Remote and Local execution of Query in 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s