public List<Customer> GetCustomers() { using (SqlConnection conn = new SqlConnection(this.connectionString)) { conn.Open(); List<Customer> list = new List<Customer>(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers"; cmd.CommandType = System.Data.CommandType.Text; using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { Customer c = new Customer(); c.Id = reader.GetString(0); c.Company = reader.GetString(1); c.ContactName = reader.IsDBNull(2) ? "" : reader.GetString(2); c.ContactTitle = reader.IsDBNull(3) ? "" : reader.GetString(3); c.Address = reader.IsDBNull(4) ? "" : reader.GetString(4); c.City = reader.IsDBNull(5) ? "" : reader.GetString(5); c.Region = reader.IsDBNull(6) ? "" : reader.GetString(6); c.ZipCode = reader.IsDBNull(7) ? "" : reader.GetString(7); c.Country = reader.IsDBNull(8) ? "" : reader.GetString(8); c.Phone = reader.IsDBNull(9) ? "" : reader.GetString(9); c.Fax = reader.IsDBNull(10) ? "" : reader.GetString(10); list.Add(c); } } return list; } }
static void Main(string[] args) { var customer = new Customer(); customer.PropertyChanged += Customer_PropertyChanged; Console.WriteLine("Changing customer ID"); customer.CustomerId = Guid.NewGuid(); Console.WriteLine("Changing customer first name"); customer.FirstName = "Paul"; Console.ReadKey(); }
partial void DeleteCustomer(Customer instance);
partial void UpdateCustomer(Customer instance);
partial void InsertCustomer(Customer instance);