Try something like this:
var allCars = _dc.Cars.Select(x => new
{
x.id,
x.vin,
PhotosCount = x.CarPhotos.Count()
});
var allCarsXml = allCars.AsEnumerable().Select(x => new XElement("Car",
new XAttribute("id", x.id),
new XAttribute("vin", x.vin),
new XAttribute("PhotosCount", x.PhotosCount)
);
var xml = new XDocument(new XStreamingElement("Cars", allCarsXml));