The following code will work for "linq for entities". Data must be in memory, made using .ToArray () for it to work, in a conversation.
XElement xml = new XElement("companies", from company in db.CustomerCompanies.AsEnumerable() orderby company.CompanyName select new XElement("company", new XAttribute("CompanyId", company.CompanyId), new XElement("CompanyName", company.CompanyName), new XElement("SapNumber", company.SapNumber), new XElement("RootCompanyId", company.RootCompanyId), new XElement("ParentCompanyId", company.ParentCompanyId) ) );
txavier
source share