Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 222973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:10:38+00:00 2026-05-11T19:10:38+00:00

I am working on an ASP.NET application using LinqToSQL. When the page loads I

  • 0

I am working on an ASP.NET application using LinqToSQL. When the page loads I run a query and save the results into a variable… var tasks = query expression. I then save this into a session variable Session["Tasks"] = tasks…

Is it possible to cast this session object back to its original var state, so I can run methods such as Count(), Reverse() and so on?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:10:39+00:00Added an answer on May 11, 2026 at 7:10 pm

    var is just short-hand for type inference… the real question here is: what is the underlying type?

    If it involves an anonymous type (i.e. new {…}, or a List<> there-of), then there is no elegant way (although it can be done in a hacky way). In short; don’t use anonymous types in this scenario…

    Note that a query expression such as IQueryable<T> is not data – it is a query – to store the data (for a cache) you’d need to use .ToList() / .ToArray() etc.

    Important: you shouldn’t store a query expression in session; at best (in-memory session provider) that will keep the data-context alive; at worst (database etc session provider) it won’t work, as a data-context isn’t serializable. Storing results from a query is fine; but otherwise, rebuild the query expression per-request.

    In which case, you might be able to use (for example):

    var tasksQuery = from task in ctx.Tasks
                 where task.IsActive
                 orderby task.Created
                 select task; // this is IQueryable<Task>
    
    Session["Tasts"] = tasksQuery.ToArray(); // this is Task[]
    ...
    var tasks = (Task[]) Session["Tasts"]; // this is Task[]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into this dilemma when working on an ASP.net web application using Web
I am working on an ASP.NET WebForm application using MVP pattern. For every Web
I am working on a web application using ASP.NET 3.5. The application has hundreds
I am working on an ASP.NET web forms application that is using Forms Authentication.
Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB.
I'm currently working on web application using VB in ASP.NET. Right now I have
I am working on big application build using ASP.NET which was started 1.5 years
I am working on a Facebook tab application. I am using asp.net MVC 2
I am working on asp.net based application. I am using multi-line textbox and I
I am working on asp.net mvc application using the mvc2 framework. Here is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.