views:

182

answers:

1

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;

THIS Bit Works Fine

foreach (var item in commonDAT)
{
  Response.Write(item.value);

}

**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"];


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.

+2  A: 

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>.

John Saunders
List<CommonSave> appcommon = (List<CommonSave>)HttpContext.Current.Application["commonRAR"];-- Will render than fail--Unable to cast object of type 'System.Linq.EnumerableQuery`1[WebServiceTEST.CommonSave]' to type 'System.Collections.Generic.List`1[WebServiceTEST.CommonSave]'.--
Chris M
Single Dimentional ones I get (like http://stackoverflow.com/questions/73542/ilistt-to-iqueryablet) its working with the class to access the list once its in the appmem that I don't get...
Chris M
I said leave it as a list. You've got (linq).ToList().ToQuery(). Just leave it as (linq).ToList().
John Saunders
Thanks for persisting through my blind dumbness there. Couldn't see the wood for the trees.
Chris M