Handle null exception in linq to xml query




var qXML = (from nm in xelement.Descendants("EmployeeFinance")
where nm.Element("Status").Value.Contains(status) && int.Parse(nm.Element("Empersonal_Id").Value) == ele.EmpId
select nm).SingleOrDefault();


Above is my sample code. Now there are instances where ele.EmpId will be present in the xml and instance where it will not be. How do i handle the null exception that is thrown when ele.EmpId is not found.


No comments:

Post a Comment