public void WhenAttachingWithNullOrDefaultPrimaryKeys() { var productAdded = TestHelpers.CreateProduct("1"); _context.Attach(productAdded); Assert.Equal(EntityState.Added, _context.Entry(productAdded).State); _context.Entry(productAdded).State = EntityState.Detached; //can attach either on the context or the DbSet _context.Product.Attach(productAdded); Assert.Equal(EntityState.Added, _context.Entry(productAdded).State); _context.Entry(productAdded).State = EntityState.Detached; _context.Product.Update(productAdded); Assert.Equal(EntityState.Added, _context.Entry(productAdded).State); _context.Entry(productAdded).State = EntityState.Detached; Assert.Throws <InvalidOperationException>(() => _context.Product.Remove(productAdded)); }