Remote Execution of Query
- 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
Local Execution of Query
- In local execution of query they get
executed in local cache.
- The biggest advantage is who data loaded
locally can be serialized.
- For each time to get Data there is no need
to go back to server.
- Using Load of local execution related
entities can be fetched together.
- 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