public void GetAllCompanies() { InsuranceServicesContext db = new InsuranceServicesContext(); var companies = db.Companies.ToArray(); List <CompanyToSend> compList = new List <CompanyToSend>(); foreach (var c in companies) { CompanyToSend cts = new CompanyToSend(); cts.Id = c.Id; cts.Name = c.Name; cts.Code = c.Code; compList.Add(cts); } //List<Company> comp = new List<Company>(); //foreach(var c in companies) //{ // Company tempCompany = new Company(); // tempCompany.Id = c.Id; // tempCompany.Name = c.Name; // tempCompany.Code = c.Code; // comp.Add(tempCompany); //} JavaScriptSerializer js = new JavaScriptSerializer(); Context.Response.Write(js.Serialize(compList)); }