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

Ask A Question

Stats

  • Questions 141k
  • Answers 142k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this: User myUser = _myDB.AccLinkSet.Include("aspnet_Users") .Where(user => user.LinkID ==… May 12, 2026 at 8:11 am
  • Editorial Team
    Editorial Team added an answer Is there a way of keeping the index in RAM… May 12, 2026 at 8:11 am
  • Editorial Team
    Editorial Team added an answer Did you add the master page as an MVC master… May 12, 2026 at 8:11 am

Related Questions

I am working on an ASP.NET web application that is required to bring up
I am working on an ASP.Net web application that must print dynamically created labels
I am currently working on an asp.net application in Visual Studio 2005. I would
I am working on an ASP.NET MVC web application, and am working on the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.