这是桌子
用户
UserId UserName Password EmailAddress
和代码..
public void ChangePassword(int userId, string password){ //code to update the password.. }
Ladislav 的答案已更新为使用 DbContext(在 EF 4.1 中引入):
public void ChangePassword(int userId, string password) { var user = new User() { Id = userId, Password = password }; using (var db = new MyEfContextName()) { db.Users.Attach(user); db.Entry(user).Property(x => x.Password).IsModified = true; db.SaveChanges(); } }