when using LINQ TO SQL, results of query dose not retrieve until you consume
results or on the other hand you iterate in results.
in example, assume you have a table in database that keeps users
specifications such as Firstname, Lastname and so on.
and assume that you use a Object Relational Designer to execute queries
against database and user's table.
by means of calling ToList() method, you force LINQ to execute
immediately and return actual results.
in conclude you can use the following code to save items in cache memory.
List<Users>
lstUsers = (List<Users>) Cache["Users"];
if (lstUsers == null)
{
SampleDataContext db = new
SampleDataContext();
lstUser = db.Users.ToList();
Cache["Users"] =
lstUser;
}
GridView1.DataSource = lstUsers;
GridView1.DataBind();
Have a good time.