0

我需要从 query2 访问可用的酒店对象,在这里我可以使用 y.key 访问 HotelCode 值,但是如何从 query2 访问可用的酒店对象。

我的矩阵模型

 public  class JsonMatrixModel
        {
            public class Result
            {

                public string responseId { get; set; }
                public string searchId { get; set; }
                public int totalFound { get; set; }
                public List<availableHotels> availableHotels { get; set; }
            }

            public class availableHotels
            {
                public string processId { get; set; }
                public string hotelCode { get; set; }
                public string availabilityStatus { get; set; }

                public double totalPrice { get; set; }
                public double totalTax { get; set; }

                public double totalSalePrice { get; set; }

                public string currency { get; set; }

                public string boardType { get; set; }
                public List<rooms> rooms { get; set; }



            }

            public class rooms
            {
                public string roomCategory { get; set; }
                public List<paxes> paxes { get; set; }
                public double totalRoomRate { get; set; }
                public List<ratesPerNight> ratesPerNight { get; set; }
            }

            public class paxes
            {
                public string paxType { get; set; }
                public int age { get; set; }


            }

            public class ratesPerNight
            {
                public string date { get; set; }
                public double amount { get; set; }
            }
        }

我的查询

Enumerable<IGrouping<string, JsonMatrixModel.availableHotels>> quer2 =
      from ff in ddd
      from ss in ff.availableHotels.OrderBy(x =>x.totalSalePrice) group ss by ss.hotelCode;

访问值

  foreach (var y in quer2)
{  
  string ss = y.Key;
}
4

2 回答 2

0

进行分组后,对一个新的匿名对象进行投影,该对象的属性将具有您的键的值,另一个可能是该键的分组值列表。

var quer2 =
      from  ff in ddd
      from  ss in ff.availableHotels.OrderBy(x =>x.totalSalePrice) 
      group ss by ss.hotelCode
      select new
      {
        GroupKey = ss.Key,      
        GroupValuesList =  ss.ToList()
      };


Console.WriteLine(quer2.First().GroupKey);
于 2014-08-28T07:37:47.263 回答
0

IGroupping 只是一个带有附加 Key 属性的 IEnumerable。这是你想要的吗?

var groups = items.GroupBy(p => p.Property);
foreach (var group in groups)
{
    Console.WriteLine(group.Key);
    foreach (var item in group)
    {
        Console.WriteLine("\t{0}", item.AnotherProperty); 
    }
}
于 2014-08-28T07:50:35.723 回答