I want to create an XML document from object list. How to handle Null in the transform.
XElement xml = new XElement("people",
from p in PPL
select new XElement("person",
new XElement("id", p.ID),
new XElement("firstname", p.FirstName),
new XElement("lastname", p.LastName),
new XElement("idrole", p.IDRole)));
As shown in the above example if the PPL is null then my xml should have just <\people> Now I am getting NUllreferenc error.
Thanks in advance
BB
One option is to use the null coalescing operator:
If you need to do this for a collection of an anonymous type, you could create an extension method:
then your query could use