How to update one field of specific records using Entity Framework?

前端 未结 6 1385
别跟我提以往
别跟我提以往 2021-01-31 11:10

I want update family of a person who his name is pejman. This is my object Class:

public class Person
{
    public int Id { get; set; }
    public string FirstNa         


        
6条回答
  •  一生所求
    2021-01-31 11:27

    For resolving this error i got values by ID from database stored in Var Temprc. Then updated the field Password which i wont to update. Then attached temprc to my Userregistrations model. Then Marked PasswordConfirm isModified. then Savechanges();

    using (var db = new Entities())
                    {                       
                        var temprc = _reg.GetUserByID(Convert.ToInt32(Session["LogedUserID"]));
                        temprc.PasswordConfirm = U.NewPassword;
                        db.Userregistrations.Attach(temprc);
                        db.Entry(temprc).Property(x => x.PasswordConfirm).IsModified = true;
                        db.SaveChanges();    
                    }
    

提交回复
热议问题