0

I'm trying to stick some data into the app so I can then build a public string get + linq query to pull out just the bits I want when I need them.

I'm just struggling to store it and then how I'd go about pulling it back out so I can query against it...

public void CommonDatatoApp() 
{
  CDataResponse cCommonData = this.GatewayReference.GetCommonData();
  var dCountries = cCommonData.PropertyCountries; //KeyValue
  var dRegions = cCommonData.Regions; //Array
  var dAreas = cCommonData.Areas; //Array
  var dResorts = cCommonData.Resorts; //Array

  var commonRAR = (from c in dCountries
                   join r in dRegions on c.Key equals r.CountryCd
                   join a in dAreas on r.Id equals a.RegionId
                   select new { c.Key, c.Value, r.Id, r.Name, dAreasID = a.Id, dAreasIDName = a.Name}
                  );


  HttpContext.Current.Application["commonData"] = commonRAR;


}
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Chris McKee
  • 4,298
  • 10
  • 48
  • 83

2 Answers2

1

The collection you're storing is an enumeration of anonymous types. When retrieving the item back from the Application[] store, you would have to cast it to IEnumerable<TYPE>, but since it's anonymous, you can't do that.

The best you can do is cast it to IEnumerable, but that's the untyped enumerable interface.

For example:

IEnumerable myList = (IEnumerable) HttpContext.Current.Application["commonData"];

foreach (object obj in myList)
{
   // do something with obj (but that will be hard, because it is of 
   // an anonymous type)
}
Philippe Leybaert
  • 168,566
  • 31
  • 210
  • 223
1

You can create a class that matches the data, and return an IQueryable<T> of that class:

public class SaveMe { 
   public string Key {get;set}
   public string Value {get;set;}
   public int Id {get;set;}
   public string Name {get;set;}
   public int dAreasID {get;set;}
   public string dAreasIDName {get;set;}
}

  var commonRAR = (from c in dCountries
                   join r in dRegions on c.Key equals r.CountryCd
                   join a in dAreas on r.Id equals a.RegionId
                   select new SaveMe {
                      Key= c.Key, 
                      Value = c.Value, 
                      Id = r.Id, 
                      Name = r.Name, 
                      dAreasID = a.Id, 
                      dAreasIDName = a.Name
                    }
                  );


  HttpContext.Current.Application["commonData"] = commonRAR;
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Cheers not quite sure what to do with it now I have it but at least it loads :l – Chris McKee Jul 16 '09 at 10:08
  • What did you want to do with it? – John Saunders Jul 16 '09 at 10:38
  • I'm trying to pull it out so i can then (a lot like your example) requery it and pull out a value or just output all the values. I cant get to the data. I tried accessing it IQueryable appCommonRar = (IQueryable)HttpContext.Current.Application["commonRAR"]; But as you can probably guess I'm pretty new to all this LINQ/.net3.5/MVC stuff and am stabbing wildly in the dark. – Chris McKee Jul 16 '09 at 10:44
  • >> http://stackoverflow.com/questions/1136705/dealing-with-linq-httpcontext-application-webservices – Chris McKee Jul 16 '09 at 10:45