字典存储在会话 [英] storing dictionary in session

查看:89
本文介绍了字典存储在会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建做会话中的对象的字典?更具体而言,我有对象的列表:MYLIST存储MYOBJECT作为与日期作为参数LINQ查询的结果

How do you create a dictionary of objects in the session? More specifically, I have a list of objects: MyList stores MyObject as the result of a linq query with the date as a parameter.

List<MyObject> Mylist;
MyList = GetObjects(TheDate);

现在,我想在会话对象存储MYLIST与日期为重点的字典。当页面需要一个特定的日期MYLIST,首先搜索词典,如果它是空白,这一天,从GetObjects查询得到的数据,并把结果保存在会话字典。

Now I'd like to store MyList in the session object in a dictionary with the date as the key. When the page needs a MyList for a specific date, first search the dictionary and if it's blank for that date, get the data from the GetObjects query and store the result in the dictionary in the session.

什么是做到这一点的最好方法是什么?

What's the best way to do this?

感谢。

推荐答案

样品用于存储会话词典:

Sample for storing a dictionary in session:

List<MyObject> Mylist;
MyList = GetObjects(TheDate);
Dictionary<DateTime> myDictionary = new Dictionary<DateTime>();
myDictionary[TheDate] = MyList;
Session["DateCollections"] = myDictionary;

从会话检索(应该有检查,以确保它的存在)示例:

Sample for retrieving from session (should have null check to be sure it's there):

Dictionary<DateTime> myDictionary  = (Dictionary<DateTime>) Session["DateCollections"];

这篇关于字典存储在会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆