1
在此查询中,我总是希望使用'normal'类型的元素。
如果设置了_includeX标志,我也需要'工作区'类型的元素。
有没有办法将它写成一个查询?或者在提交查询之前建立基于_includeX的where子句?在Linq查询中构建'where'子句
if (_includeX) {
query = from xElem in doc.Descendants(_xString)
let typeAttributeValue = xElem.Attribute(_typeAttributeName).Value
where typeAttributeValue == _sWorkspace ||
typeAttributeValue == _sNormal
select new xmlThing
{
_location = xElem.Attribute(_nameAttributeName).Value,
_type = xElem.Attribute(_typeAttributeName).Value,
};
}
else {
query = from xElem in doc.Descendants(_xString)
where xElem.Attribute(_typeAttributeName).Value == _sNormal
select new xmlThing
{
_location = xElem.Attribute(_nameAttributeName).Value,
_type = xElem.Attribute(_typeAttributeName).Value,
};
}