不確定這是否可能。我有一個'MarketInventory'節點的子集:項目屬性值
<MARKET_INVENTORY _Type="TotalSales" _MonthRangeType="Prior7To12Months" _Count="18"/>
<MARKET_INVENTORY _Type="TotalSales" _MonthRangeType="Prior4To6Months" _Count="6"/>
<MARKET_INVENTORY _Type="TotalSales" _MonthRangeType="Last3Months" _Count="11"/>
<MARKET_INVENTORY _Type="TotalSales" _TrendType="Stable"/>
在_Type =「TotalSales」節點上過濾。
我不知道是否有可能投影_COUNT值屬性引入到這個類:
public class MarketInventoryListing
{
public string Prior7To12Months { get; set; }
public string Prior4To6Months { get; set; }
public string LastThreeMonths { get; set; }
}
這是據我得到:
var marketInventoryTotalListings = from totalListings in xe.Descendants("MARKET_INVENTORY")
where (string) totalListings.Attribute("_Type") == "TotalSales"
select new MarketInventoryListing()
{
Prior7To12Months =
(
from thing in totalListings.Descendants()
where (string)totalListings.Attribute("_MonthRangeType") == "Prior7To12Months"
select thing.Attribute("_Count").Value
)
};
''Prior7To12Months''的類型是string''的''而LINQ查詢返回''IEnumerable的'' –