.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> LINQ >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Remote and Local execution of Query in LINQ

Posted By:Dhananjay Kumar       Posted Date: January 06, 2011    Points: 75    Category: LINQ    URL: http://www.dotnetspark.com  

Remote and Local execution of Query in LINQ. This query executes on the server. Remote execution of query is default in LINQ.
 

Remote and Local execution of Query in LINQ

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



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.




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



 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend