使用LINQ / HttpContext.Application和放大器处理; Web服务 [英] Dealing with LINQ / HttpContext.Application & WebServices
问题描述
我有以下功能+ code解析和查询Web服务请求,那么在理论上把结果存储在应用程序(如只需要一天,而幸运的是刷新一次,当应用程序刷新)。
I have the following function + code to parse and query a webservice request then in theory store the results in the application (as it only needs to refresh once a day, which luckily is when the application refreshes).
//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(**
**Ideally I want to then pull it out of the appmemory so I can then access the data, which is where I've tried various (probably stupid) methods to use the information. Just pulling it out is causing me issues :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())的 简单的例子的
Answer as Marked(remove the .AsQueryable() ) Quick Example
只是为了让这一个详细的答案,一个快速的方法来重新查询并显示一个结果......
Just to make this a verbose answer, a quick way to re-query and display a resultset...
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>");
}
使用的人的
希望。
Hopefully of use to someone.
推荐答案
如果你要查询一次以上,那么为什么不把它作为一个列表?该类型是名单,其中,CommonSave&GT;
If you're going to query it more than once, then why not just leave it as a list? The type will be List<CommonSave>
.
这篇关于使用LINQ / HttpContext.Application和放大器处理; Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!