我有以下函数 + 代码来解析和查询 Web 服务请求,然后理论上将结果存储在应用程序中(因为它每天只需要刷新一次,幸运的是当应用程序刷新时)。
//tocommondata is a reference to the common stuff in the webservice
var dCountries = toCommonData.PropertyCountries; //KeyValuePair
var dRegions = toCommonData.Regions;//Array
var dAreas = toCommonData.Areas;//Array
var commonDAT = (from c in dCountries
join r in dRegions on c.Key equals r.CountryCode
join a in dAreas on r.Id equals a.RegionId
join p in dResorts on a.Id equals p.AreaId
select new CommonSave
{
Key = c.Key,
Value = c.Value,
Id = r.Id,
Name = r.Name,
dAreasID = a.Id,
dAreasName = a.Name,
}
).ToList().AsQueryable();
HttpContext.Current.Application["commonDAT"] = commonDAT;
这个位工作正常
foreach (var item in commonDAT)
{
Response.Write(item.value);
}
**理想情况下,我想将其从 appmemory 中拉出,这样我就可以访问数据,这是我尝试各种(可能是愚蠢的)方法来使用信息的地方。只是把它拔出来就会引起我的问题:o( **
//This Seems to kinda work for at least grabbing it (I'm probably doing this REALLY wrong).
IQueryable appCommonRar = (IQueryable)HttpContext.Current.Application["commonDAT"];
回答为标记(删除 .AsQueryable() ) 快速示例
只是为了使它成为一个冗长的答案,一种重新查询和显示结果集的快速方法......
List<CommonSave> appcommon = (List<CommonSave>)HttpContext.Current.Application["commonDAT"];
Response.Write(appcommon.Count()); // Number of responses
var texst = (from xs in appcommon
where xs.Key == "GBR"
select xs.dAreasName
);
foreach (var item in texst)
{
Response.Write("<br><b>"+item.ToString()+"<b><br>");
}
希望对某人有用。