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>");
}
希望對某人有用。
列表 appcommon =(列表)HttpContext.Current.Application [「commonRAR」]; - 將呈現比失敗 - 無法將類型爲'System.Linq.EnumerableQuery`1 [WebServiceTEST.CommonSave]'的對象轉換爲鍵入'System.Collections.Generic.List`1 [WebServiceTEST.CommonSave]' 。 - –
2009-07-16 11:02:23