public async Task <IActionResult> Edit(int id, [Bind("guid,name,password,salt,createdOn,id")] Customer customer) { if (id != customer.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(customer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(customer.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(customer)); }
/// <summary> /// 通过id更新一个实体的所有属性 /// </summary> /// <returns>The update.</returns> /// <param name="entity">Entity.</param> public bool Update(T entity) { //T res = _context.Set<T>().Where(x => x.Id == entity.Id).First(); //res = entity; _context.Update(entity); return(SaveChanges()); //_context.SaveChanges(); //var entry = this._context.Entry(entity); //entry.State = EntityState.Modified; ////如果数据没有发生变化 //if (!_context.ChangeTracker.HasChanges()) //{ // return; //} }