考虑以下代码
IEnumerable<String> query = null;
query = from x in xml.Descendants(xmlMasterContainerName).Descendants(xmlElementName)
let guid = x.Attribute("guid") ?? new XAttribute("guid", "-1")
where x.Attribute(xmlAttributeIdName).Value == xmlAttributeIdValue
select guid.Value;
尝试 query.ToList() 时出现“未设置对象引用”
当 'x.Attribute(xmlAttributeIdName).Value == xmlAttributeIdValue' 不存在时,这很可能是由 'select guid.Value' 引起的。
如何在选择之前检查现有值的 where 语句?谢谢