I believe that he objects to the fact that you are using the XElement constructor, which takes parameters in your select clause. Since XElement does not have a constructor without parameters, you may need to modify your code to select an anonymous type, and initialize the XElement collection after the fact.
var els = from c in db.Contacts orderby c.ContactID select new { c.ContactID, c.FirstName, c.LastName }; var xml = new XElement("contacts", els.ToList() .Select(e => new XElement("contact", new XAttribute("contactID", e.ContactID), new XElement("firstName", e.FirstName), new XElement("lastName", e.LastName))));
This is untested, but hopefully gives you this idea. First I make an EF request, and then I call ToList () so that I can select the XElement collection using Linq for objects, not EF.
Matt hamilton
source share