我试图使用以下方法从XML的回复中填满IE amountable<Resort supplementier>
。 LINQ Query: How do I populatione/create IList<PerPricing> PricingDetail
within my LINQ query? 在目前情况下将有一个项目(PerPricing)(IList<PerPricing>
)。 它需要成为未来选择的IList,并支持其他一些功能。 我的错误之处在于:
var resortPricing =
xDoc.Elements("ResortPricingRS")
.Elements("ResortPricing")
.GroupBy(x => new
{
ID = x.Element(XName.Get("ResortId")).Value
}
)
.Select(x => new ResortSupplier
{
SupplierCode = x.Key.ID,
ResortProducts = x.Select(i => new Product
{
Code = i.Element("RoomCategory").Value,
Description = i.Element("CategoryDesc").Value,
Rating = (i.Elements("StarRatingCode").Any() ? i.Element("StarRatingCode").Value : ""),
PricingDetail = {
new PerPricing {
PricingType = "PerRoom",
GroupNumber = 1
Price = decimal.Parse(i.Elements("TotalPrice").Any() ? i.Element("TotalPrice").Value : "0"),
PricingError = (i.Elements("PricingError").Any() ? new Error { ErrorCode = i.Element("PricingError").Value } : null)
}
}
}
).ToList()
}
).OrderBy(x => x.SupplierCode);
我的目标如下:
[Serializable]
public class ResortSupplier
{
public string SupplierCode { get; set; }
public IList<Product> ResortProducts { get; set; }
}
[Serializable]
public class Product
{
public string Code { get; set; }
public string Description { get; set; }
public string Rating { get; set; }
public IList<PerPricing> PricingDetail { get; set; }
}
[Serializable]
public class PerPricing
{
public string PricingType { get; set; }
public int GroupNumber { get; set; }
public decimal? Price { get; set; }
public Error PricingError { get; set; }
}