public Customer Update(Customer pCustomers) { var entity = Context.Attach(pCustomers); entity.State = EntityState.Modified; return(pCustomers); }
public void UpdateCustomerTest() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); using (var context = new NorthWindContext(ContextSqlLiteOptions(connection))) { context.Database.EnsureCreated(); } using (var context = new NorthWindContext(ContextSqlLiteOptions(connection))) { context.Countries.AddRange(GetCountriesForSqlLite()); context.SaveChanges(); context.Customers.AddRange(MockedSqlLiteCustomers()); context.SaveChanges(); } Customer thisCustomer; using (var context = new NorthWindContext(ContextSqlLiteOptions(connection))) { thisCustomer = context.Customers .FirstOrDefault(customer => customer.CompanyName == "Around the Horn"); } // ReSharper disable once PossibleNullReferenceException thisCustomer.CompanyName = thisCustomer.CompanyName + "1"; using (var context = new NorthWindContext(ContextSqlLiteOptions(connection))) { context.Attach(thisCustomer).State = EntityState.Modified; context.SaveChanges(); } using (var context = new NorthWindContext(ContextSqlLiteOptions(connection))) { Assert.IsNotNull(context.Customers.FirstOrDefault(cust => cust.CompanyName == "Around the Horn1"), "Expected to find Around the Horn1 in SqlLite update test"); } }