private void button2_Click(object sender, EventArgs e) { context = new DafestyEntities(); // Get existing Customer Customer c = context.Customers.First(x => x.CustomerID == "1001"); label1.Text = $"{c.CustomerName} {c.MemberRating}"; // Change customer's member rating c.MemberRating = "B"; label1.Text = $"{c.CustomerName} {c.MemberRating}"; // Create new customer var newCustomer = new Customer(); newCustomer.CustomerID = "1007"; newCustomer.CustomerName = "Bond"; newCustomer.MemberRating = "Z"; // Add new customer to Customers collection context.Customers.Add(newCustomer); // Fetch customer var deleteCustomer = context.Customers.First(x => x.CustomerID == "1007"); // Remove customer context.Customers.Remove(deleteCustomer); // Save Changes to sync DB context.SaveChanges(); }
public Form1() { InitializeComponent(); context = new DafestyEntities(); }