How can I check whether the value for an attribute is not null, inside the LINQ query. If it is not null then add the attribute to the XML element?
for ex : First = AAA, Last = BBB, Suffix = Jr. Then my XML should look like (As I didn't pass any value for Prefix and type they should not appear in the XML)
<Subject>
</Name First= "AAA" Last ="BBB" Suffix="Jr">
</Subject>
Thanks BB
from i in DriverNames
select new XElement(Subject,
new XElement(Name,
new XAttribute("type", i.nameType),
new XAttribute(First, i.First.ToString().Trim().ToUpper()),
new XAttribute(last, i.Last.ToString().Trim().ToUpper()),
new XAttribute(Prefix, i.Prefix.ToString().Trim().ToUpper()),
new XAttribute(Suffix, i.Suffix.ToString().Trim().ToUpper())
) )