Solved

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

Posted on 2011-09-05
3
1,823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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