2009-07-16 73 views
0

我有以下函数+代码来解析和查询Web服务请求,然后理论上将结果存储在应用程序中(因为它只需要每天刷新一次,幸运的是当应用程序刷新)。处理LINQ/HttpContext.Application&WebServices

//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>"); 
} 

希望对某人有用。

回答

2

如果你打算多次查询它,那么为什么不把它作为一个列表呢?该类型将是List<CommonSave>

+0

列表 appcommon =(列表)HttpContext.Current.Application [“commonRAR”]; - 将呈现比失败 - 无法将类型为'System.Linq.EnumerableQuery`1 [WebServiceTEST.CommonSave]'的对象转换为键入'System.Collections.Generic.List`1 [WebServiceTEST.CommonSave]' 。 - – 2009-07-16 11:02:23