dominicwong
asked on
how to fix this LINQ-XML expression
Hi experts
I am new to LINQ-XML, I wonder how to fix this expression. Thanks in advance,
There is an exception since 'tgSetting.TgIDs' can be 'null'.
var e = from tgSetting in tgSettings
select new XElement("Tg", new XAttribute("Name", tgSetting.TgListName),
new XElement("Tgrp",from tgID in tgSetting.TgIDs
where tgID != null
select new XElement("Tg", new XAttribute("Number", tgID.ToString()))));
What I would like to have is if it is 'null', then output the following:
<Tg Name="gp 0">
<Tgrp>
</Tgrp>
</Tg>
I am new to LINQ-XML, I wonder how to fix this expression. Thanks in advance,
There is an exception since 'tgSetting.TgIDs' can be 'null'.
var e = from tgSetting in tgSettings
select new XElement("Tg", new XAttribute("Name", tgSetting.TgListName),
new XElement("Tgrp",from tgID in tgSetting.TgIDs
where tgID != null
select new XElement("Tg", new XAttribute("Number", tgID.ToString()))));
What I would like to have is if it is 'null', then output the following:
<Tg Name="gp 0">
<Tgrp>
</Tgrp>
</Tg>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help.
ASKER
'There is no implicit conversion between 'string' and 'System.Collections.Generi