Solved

how to store and retrieve Linq List into session variable in c#

Posted on 2011-09-05
3
1,729 Views
Last Modified: 2013-11-11
This is how i am storing my linq list into session. How would I retrive it back from session

 DataClassesDataContext myContext = new DataClassesDataContext();

        var QuestionList = myContext.sp_GetQuestionsByChapterID(Session["QuizID"].ToString()).ToList();

        Session["QuestionsList"] = QuestionList;

I have tried something like this to retrive it back from session

var QuestionList=  Session["QuestionsList"] ;
int QuestionID = (int)QuestionList[CurrentPos].QuestionID;

this is giving me an error
"Cannot apply indexing with [] to an expression of type 'object'"


0
Comment
Question by:mmalik15
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Kusala Wijayasena
ID: 36485945
What would be the type of "QuestionList" ? Is it "List<Question>" ?

If "QuestionList" is "List<Question>", you can retrieve as follows

List<Question> questions = (List<Question>)Session["QuestionsList"];
int questionID = questions[CurrentPos].QuestionID;

Open in new window


-Kusala

 
0
 

Author Comment

by:mmalik15
ID: 36486021
thanks for comment
I store QuestionList  in var like this, var QuestionList  but using it as an arraylist. Can we convert the session into arraylist?
0
 
LVL 11

Accepted Solution

by:
Kusala Wijayasena earned 500 total points
ID: 36491404
You can cast it like this:

ArrayList questionList =  (ArrayList)Session["QuestionsList"];

Open in new window


-Kusala
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question