asp.net mvc - Cannot update single property in Entity Framework -
i'm trying update single property of entity cannot update it.
here have done far:
public async task changepassword(string user, string password) { using (var context = new abccontext()) { var user = await context.members.where(c => c.username == user).firstordefaultasync(); var member = context.members.find(user.personid); var coolblog = new member { personid = member.personid, password = member.password }; context.configuration.validateonsaveenabled = false; context.members.attach(member); context.entry(member).property(c => c.password).originalvalue = coolblog.password.tostring(); context.entry(member).property(m => m.password).ismodified = true; await context.savechangesasync(); }; } it not updating password property in database. please guide me have searched internet couldn't find appropriate solution.
you want this:
public async task changepassword(string user, string password) { using (var context = new abccontext()) { var user = await context.members.where(c => c.username == user).firstordefaultasync(); if (user != null) { user.password = password; // hashing on password not store plain password await context.savechangesasync(); } } }
Comments
Post a Comment