public static CustomerModel Get(string name) { var db = new NorthwindEntities(); var customer = db.Customers.Where(c => c.CompanyName == name).Select(c => new CustomerModel { Name = c.CompanyName, ContactName = c.ContactName, ContactTitle = c.ContactTitle, Address = c.Address, City = c.City, Country = c.Country, Phone = c.Phone, Fax = c.Fax }) .FirstOrDefault(); return customer; }
protected void Page_Load(object sender, EventArgs e) { var db = new NorthwindEntities(); customers = db.Customers.Select(c => new CustomerModel { Name = c.CompanyName, ContactName = c.ContactName, ContactTitle = c.ContactTitle, Address = c.Address, City = c.City, Country = c.Country, Phone = c.Phone, Fax = c.Fax }) .ToList(); this.GridViewCustomers.DataSource = customers; this.DataBind(); }