过滤此Linq查询
本文关键字:查询 Linq 过滤 | 更新日期: 2023-09-27 18:04:46
我想使用这个查询:
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
匿名类型检索内容的附加条件,其值必须等于"*"
。
为什么我不明白?我想我对匿名类型或=>
操作符了解得不够。
这是你想要的吗?
mainView.DataSource = organizedData.Where(x => x.Custom == "*").ToList();
我想这就是你要找的。我把这个值放在一个临时变量中,这样就不需要计算两次了。
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,
};