Deffered Execution in Linq

LINQ is Langauage Integrated Query.
Here is Deffered Execution in LINQ –

Suppose there is a Generic List of Employee –

List listOfEmployee = new List();
Employee emp1 = new Employee(10, “Deepak”, “Pune”, 100000, 5);
listOfEmployee.Add(emp1);
Employee emp2 = new Employee() { EmpNo = 20, Name = “Pankaj”, City = “Jalgaon”, Experience = 3, Salary = 80000 };
listOfEmployee.Add(emp2);

Employee emp3 = new Employee();
emp3.EmpNo = 30;
emp3.Experience = 6;
emp3.Name = “Rijwan”;
emp3.Salary = 150000;
emp3.City = “Satara”;
listOfEmployee.Add(emp3);

Employee emp4 = new Employee() { EmpNo = 40, Name = “Kalyani”, City = “Patna”, Experience = 2, Salary = 60000 };
listOfEmployee.Add(emp4);

Employee emp5 = new Employee() { EmpNo = 50, Name = “Shriniwas”, City = “Pune”, Experience = 8, Salary = 200000 };
listOfEmployee.Add(emp5);

IEnumerable emps = from e in listOfEmployee //Deepak,Pankaj,Rijwan,Shriniwas
where e.Salary >= 80000
select e;

Now we print the records of Linq Results —-
Console.WriteLine(“\n=================Before Deffered Execution=================\n”);
foreach (var emp in emps)
{
Console.WriteLine(“\tEmployee Name:{0}”, emp.Name);
}

now we are adding another employee in the current list….

Employee emp6 = new Employee() { EmpNo = 60, Name = “Ajay”, City = “Mumbai”, Experience = 1, Salary = 90000 };
listOfEmployee.Add(emp6);

Console.WriteLine(“\n=======After Updations in Actual List without updating the LINQ results========\n”);
foreach (var emp in emps)
{

Console.WriteLine(“\tEmployee Name:{0}”, emp.Name);

}

================= End of Example ================

In Above code after adding naother employee in List it got automatically updated in LINQ results…This concept is nothing but a Deffered Execution in LINQ.

Advertisements
Posted in .NET Framework, LINQ | Leave a comment

Disable Right Click using JQuery.

Add below JQuery function in Script tag of aspx page.

$( function ()
{
$( this ).bind( “contextmenu”, function ( e )
{
e.preventDefault();
});

}

Posted in JQuery | Tagged , | Leave a comment

Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Posted in General | 2 Comments