Archive for April 13th, 2009

How LINQ Works

To use LINQ in your program you need a LINQ expression. Then then return type of LINQ expression is an iterator object that implements IEnumerable<T> and enumerating over the iterator object, LINQ performs its work. However this makes some questions about  LINQ

  • How LINQ works?
  • How LINQ execute statements?
  • How LINQ filter results?

LINQ works differently for different type of data type for example if you are using LINQ with database then it open database connections, perform SQL commands and return requested results back to you. In case of LINQ to objects LINQ simply perform uses for each loop to scan through the collection and return result back to you.

LINQ to objects is always slower as compare to comparable for each block, because this overhead is due to additional methods and delegate works. If you want to implement a advance search routine for in memory objects then un this case using LINQ will be a good idea as compare to for each block.

There are some point to remember while using LINQ to objects

  1. LINQ expressions work on objects that implement Enumerable<T> and LINQ
    expressions return objects that implement IEnumerable<T>.

ASP.NET State Management

As we all know that HTTP is a stateless protocol means when after each request client is disconnected from server and discards objects that were created for the page. Drawback of this architecture is that you have to store the information between the server request while on the other side this architecture enable web applications to scale up and servers can responds to thousands of simultaneous requests without running out of server
memory. includes a variety of state management options. A developer can choose right option for state management option depending upon data you need to store, duration for which data has to be stored, data scope and security and performance considerations.

There are three options available for state management in

  • View State
  • Query String
  • Custom Cookies
  • Caching
  • Profiles

In addition to this you can also write a custom state management module for your application and use database or file system for storing state information but this will bring some performance issues to your application because for retrieving and storing state information you need to establish database connections. 

we will discuss management options in more details in upcoming posts.