我想使用此查询:
var queryData = from va in xdoc.Descendants("language")
select new
{
StringID = va.Parent.Parent.Attribute("id").Value,
Language = va.Attribute("name").Value,
LanguageData = va.Element("value").Value,
};
var organizedData = from x in queryData
group x by x.StringID into xg
select new
{
StringID = xg.Key,
English = xg.SingleOrDefault(x => x.Language == "ENGLISH_US").LanguageData,
Custom = xg.SingleOrDefault(x => x.Language == languageBox.SelectedItem.ToString()).LanguageData,
};
mainView.DataSource = organizedData.ToList();
mainView.Refresh();
除了作为Custom
匿名类型检索内容的附加条件之外,其值必须等于"*"
。
为什么我不知道这个?我想我对匿名类型或=>
运算符知之甚少。
答案 0 :(得分:3)
这就是你想要的吗?
mainView.DataSource = organizedData.Where(x => x.Custom == "*").ToList();
答案 1 :(得分:2)
我认为这就是你要找的东西。我将值放在临时变量中,因此不必计算两次。
var organizedData = from x in queryData
group x by x.StringID into xg
let temp = xg.SingleOrDefault(x => x.Language == languageBox.SelectedItem.ToString()).LanguageData
where temp == "*"
select new
{
StringID = xg.Key,
English = xg.SingleOrDefault(x => x.Language == "ENGLISH_US").LanguageData,
Custom = temp,
};