我有一个相当简单的 Linq 查询(简化代码):
dim x = From Product In lstProductList.AsParallel
Order By Product.Price.GrossPrice Descending Select Product
产品是一类。Product.Price 是一个子类, GrossPrice 是它的属性之一。为了计算出我需要使用 Session("exchange_rate") 的价格。
因此,对于 lstProductList 中的每个项目,都有一个执行以下操作的函数:
NetPrice=NetPrice * Session("exchange_rate")
(然后 GrossPrice 返回 NetPrice+VatAmount)
无论我尝试了什么,我都无法访问会话状态。
我已经尝试过 HttpContext.Current - 但没有返回任何内容。我已经在类上尝试了实现 IRequiresSessionState(这有助于通用 http 处理程序 [.ashx] 中的类似情况) - 没有运气。
我正在使用简单的 InProc 会话状态模式。汇率必须是用户特定的。
我能做些什么?
我正在使用:Web 开发、.Net 4、VB.net
一步一步:
page_load (in .aspx)
dim objSearch as new SearchClass()
dim output = objSearch.renderProductsFound()
然后在 objSearch.renderProductsFound:
lstProductList.Add(objProduct(1))
...
lstProductList.Add(objProduct(n))
dim x = 从 lstProductList.AsParallel 中的产品
按 Product.Price.GrossPrice 降序选择产品
在 Product.Price.GrossPrice 中获取:
返回 me.NetPrice+me.VatAmount
在 Product.Price.NetPrice 中获取:
return NetBasePrice*Session("exchange_rate")
再次,简化代码,这里粘贴太多了。如果我将查询解包到 For 循环中,则工作正常。