I'm generating some XML with the following code, however the system I'm working on uses manual loading instead of lazy loading within the EntityFramework. So in effect, I have to call EnsureLoaded() to explicitly say what elements need loading. The problem is calling EnsureLoaded() withing deeply nested fields. Here is my code;\[code\]public partial class Test{ public XElement ReturnDetails() { Test.DriverReference.EnsureLoaded(); return new XElement("Test", new XAttribute("CarNum", CarNum), new XAttribute("Make", Make ?? string.Empty), new XAttribute("Model", Model ?? string.Empty), new XAttribute("Colour", Colour ?? string.Empty), new XElement("Drivers", from driver in Drivers select new XElement("Driver", new XAttribute("DriverNum", driver.DriverNum), new XAttribute("Notes", driver.Notes), new XElement("Routes"), from route in driver.Routes select new XElement("Route", new XAttribute("Name", route.Name), new XAttribute("Notes", route.Notes) )))); }}\[/code\]The problem is getting the value of Driver, and keep getting NullReferenceExceptions when going beyond three level of Entity hierarchies. What I want to do is the following;\[code\]public partial class Test{ public XElement ReturnDetails() { Test.DriverReference.EnsureLoaded(); return new XElement("Test", new XAttribute("CarNum", CarNum), new XAttribute("Make", Make ?? string.Empty), new XAttribute("Model", Model ?? string.Empty), new XAttribute("Colour", Colour ?? string.Empty), new XElement("Drivers", from driver in Drivers.EnsureLoaded() ***** select new XElement("Driver", new XAttribute("DriverNum", driver.DriverNum), new XAttribute("Notes", driver.Notes), new XElement("Routes"), from route in driver.Routes.EnsureLoaded() ***** select new XElement("Route", new XAttribute("Notes", route.Notes), new XAttribute("Name", route.Name) )))); }}\[/code\]