In this article I am going to explain difference
between Deferred & Immediate Query Execution in LINQ.
In Deferred Execution query is not executed at the time
of declaration. When the query object iterated over a loop then its executed.
In Immediate Execution query is got executed when it
declared.
Deferred
Execution:
Now we will see both by using an example. For this I
created a Visual Studio Solution. Here In my solution I added a new Class
Employee Like below:

Image 1.
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
namespace
DeferredVsImmediate_Query
{
public class Employee
{
public int Emp_ID { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Country { get; set; }
}
}
Add a New Web
Page Default.aspx and Add Below Code:
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
namespace
DeferredVsImmediate_Query
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var Emp_List = new List<Employee>(
new Employee[]
{
new Employee{Emp_ID=1, Name="Shambhu
Sharma",
Email="shambhu@shambhu.com", Country="India"},
new Employee{Emp_ID=2, Name="Manu
Khanna",
Email="manu@manu.com", Country="India"},
new Employee{Emp_ID=3, Name="Abhishek
Nigam",
Email="abhishek@abhishek.com", Country="USA"},
new Employee{Emp_ID=4, Name="Yogesh
Gupta",
Email="yogesh@yogesh.com", Country="USA"},
new Employee{Emp_ID=5, Name="Shweta
Kashyap",
Email="Shweta@Shweta.com", Country="India"},
new Employee{Emp_ID=6, Name="Shraddha
Gaur",
Email="Shraddha@Shraddha.com", Country="India"},
new Employee{Emp_ID=7, Name="Akhilesh
Atwal",
Email="Akhilesh@Akhilesh.com", Country="India"},
new Employee{Emp_ID=6, Name="Mayank
Dhulekar",
Email="Mayank@Mayank.com", Country="USA"},
new Employee{Emp_ID=7, Name="Saurabh
Mehrotra",
Email="Saurabh@Saurabh.com", Country="USA"},
new Employee{Emp_ID=7, Name="Mehak
Jain",
Email="Mehak@Mehak.com", Country="India"},
});
var Result = from a in Emp_List
where a.Country.Equals("India")
select new { a.Name };
foreach (var EMP in Result)
Response.Write(EMP.Name + "</br>");
}
}
}
Now Run Your
Application:

Image 2.
Now we will see when my query executed:

Image 3.
Now Add a new record after your query to see deferred
execution:

Image 4.
Now run your app:

Image 5.
Immediate
Execution: We
can force our query to execute immediately like below:

Image 6.
Now run your application:

Image 7.
Now See Both:

Image 8.