0

I have this method :

public void Update(DBS.BankAccount entity) { try { using (var _nahidContext = new NahidContext()) { _nahidContext.BankAccounts.Attach(entity); var bankAccountElement = _nahidContext.Entry(entity); bankAccountElement.CurrentValues.SetValues(entity); _nahidContext.SaveChanges(); //__________ or ___________ //var bankAccountElement = FindById(entity.Id); //if (_nahidContext.Entry(bankAccountElement).State == System.Data.Entity.EntityState.Detached) //{ // _nahidContext.BankAccounts.Attach(bankAccountElement); //} ////_nahidContext.Entry(bankAccountElement).State = System.Data.Entity.EntityState.Modified; //_nahidContext.SaveChanges(); } } catch (Exception ex) { throw new ArgumentException(ex.Message); } } 

Which run without any error but my bankAccountElement does not change. Please help me.

1 Answer 1

2

First you attach (entity state= unchanged), then you set values with same values than attached entity, so it keeps unchanged.

You should do this

 _nahidContext.BankAccounts.Attach(entity); var bankAccountElement = _nahidContext.Entry(entity); bankAccountElement.State = EntityState.Modified; 

You can read more here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.