Solved

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

Posted on 2011-09-05
3
1,634 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now