0

我正在尝试将一些数据粘贴到应用程序中,这样我就可以构建一个公共字符串 get + linq 查询,以便在我需要它们时只提取我想要的位。

我只是在努力存储它,然后我将如何将它拉回来以便我可以查询它......

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;


}
4

2 回答 2

1

您存储的集合是匿名类型的枚举。从 Application[] 存储中取回项目时,您必须将其强制转换为IEnumerable<TYPE>,但由于它是匿名的,因此您不能这样做。

您能做的最好的事情就是将其转换为IEnumerable,但这是无类型的可枚举接口。

例如:

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)
}
于 2009-07-15T11:33:55.333 回答
1

您可以创建一个与数据匹配的类,并返回IQueryable<T>该类的一个:

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;
于 2009-07-15T11:53:56.103 回答