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 694001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:48:43+00:00 2026-05-14T02:48:43+00:00

I have a fairly simple Linq query (simplified code): dim x = From Product

  • 0

I have a fairly simple Linq query (simplified code):

dim x = From Product In lstProductList.AsParallel 
        Order By Product.Price.GrossPrice Descending Select Product

Product is a class. Product.Price is a child class and GrossPrice is one of its properties. In order to work out the price I need to use Session(“exchange_rate”).

So for each item in lstProductList there’s a function that does the following:

NetPrice=NetPrice * Session("exchange_rate")

(and then GrossPrice returns NetPrice+VatAmount)

No matter what I’ve tried I cannot access session state.

I have tried HttpContext.Current – but that returns Nothing.
I’ve tried Implements IRequiresSessionState on the class (which helps in a similar situation in generic http handlers [.ashx]) – no luck.

I’m using simple InProc session state mode. Exchange rate has to be user specific.

What can I do?

I’m working with:
web development, .Net 4, VB.net


Step-by-step:
page_load (in .aspx)
dim objSearch as new SearchClass()
dim output = objSearch.renderProductsFound()

then in objSearch.renderProductsFound:
lstProductList.Add(objProduct(1))
…
lstProductList.Add(objProduct(n))

dim x = From Product In lstProductList.AsParallel
Order By Product.Price.GrossPrice Descending Select Product

In Product.Price.GrossPrice Get :
return me.NetPrice+me.VatAmount

In Product.Price.NetPrice Get:
return NetBasePrice*Session(“exchange_rate”)

Again, simplified code, too much to paste in here. Works fine if I unwrap the query into For loops.

  • 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-14T02:48:43+00:00Added an answer on May 14, 2026 at 2:48 am

    I’m not exactly sure how HttpContext.Current works, but I wouldn’t be surprised if it would work only on the main thread that is processing the HTTP request. This would mean that you cannot use it on any other threads. When PLINQ executes the query, it picks some random threads from the thread pool and evaluates the predicates in the query using these threads, so this may be the reason why your query doesn’t work.

    If the GrossPrice property needs to access only a single thing from the session state, it should be fairly easy to change it to a method and pass the value from the session state as an argument:

    Dim rate = Session("exchange_rate")
    Dim x = From product In lstProductList.AsParallel  
            Order By product.Price.GetGrossPrice(rate) Descending 
            Select product 
    

    Depending on where you use x later, you could also add a call to ToList to force the evaluation of the query (otherwise it may be executed lazily at some later time), but I think the change I described above should fix it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly simple piece of code that retrieves an object from the
I have a fairly simple query: SELECT invoice_id WHERE employee_id = 'XXXX' AND customer_id
I have a fairly simple block of code. Sub Run(Name) on error resume next
I have a fairly complex LINQ to Entities query I'd like to try compiling
I have what should be a fairly simple requirement. I want to use LINQ
I am learning LINQ and this seems like a fairly simple problem. I have
I have a fairly simple piece of code: Private _PurchaseDelivery as PurchaseDelivery Protected Overrides
I have a LINQ query: var result = from mt in MessageTypes join mtfmt
I have a fairly simple expression parser that uses the Linq.Expression namespace. Input is
I have a fairly simple const struct in some C code that simply holds

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.