public List<CustomerInfo> ListCustomersXml() { using (var ctx = new AdventureWorksLT2008_DataEntities()) { var listCustomers = ctx.Customers.Select(c => new CustomerInfo { Email = c.EmailAddress, FirstName = c.FirstName, LastName = c.LastName }).OrderBy(c => c.Email).Skip(10).Take(10).ToList(); return listCustomers; } }
// // GET: /mvc/rest/list/customers public ContentResult Index() { List<CustomerInfo> listCustomers; using (var ctx = new AdventureWorksLT2008_DataEntities()) { listCustomers = ctx.Customers.Select(c => new CustomerInfo { Email = c.EmailAddress, FirstName = c.FirstName, LastName = c.LastName }).OrderBy(c => c.Email).Skip(40).Take(10).ToList(); } var serialize = new JsonSerializer(); var sb = new StringBuilder(); var writer = new StringWriter(sb); serialize.Serialize(new JsonTextWriter(writer), listCustomers); return new ContentResult { Content = sb.ToString(), ContentType = "application/json" }; }