Three alternatives. Use specific version instead of Object:
zyon.Entry<TB_Cliente>( client ).State = System.Data.Entity.EntityState.Modified;
Go straight to ChangeTracker
make the change:
zyon.ChangeTracker.Entries<TB_Cliente>().First( x => x.Entity == client ).State = System.Data.Entity.EntityState.Modified;
Or, if it is a particular code snippet, and you are already tired of the somewhat mysterious EF errors, do both:
zyon.TB_Cliente.Attach( client );
zyon.Entry( client ).State = System.Data.Entity.EntityState.Modified;
zyon.ChangeTracker.Entries<TB_Cliente>().First( x => x.Entity == client ).State = System.Data.Entity.EntityState.Modified;
zyon.SaveChanges();
For documentation, DbContext.Entry(object)
should be a valid way to access the properties of a tracked or attached object, and change State to Modified would be all necessary to force the data UPDATE. But from time to time does not scroll, simply.
The generic version, if you want to update several objects in an immediate way (and outside the official transaction!):
public void DetachedUpdate(T obj)
{
using (var context = new Context())
{
context.Set<T>().Attach(obj);
context.ChangeTracker.Entries<T>().First(e => e.Entity == obj).State = EntityState.Modified;
context.SaveChanges();
}
}
Put the code to all your action Edit to make it clearer ?
– Érik Thiago
That’s the whole code.
– Aline
This existing database was created by the application?
– Leonel Sanches da Silva
No. Old bank.
– Aline
Solved the problem?
– Renan
I already had this error, I concerted doing the following: First I search the bank who I want to edit : var Client = 'context.entidade.firstOrDefault(x=> x.Id == Iddocliente); Ai start editing: Client.name = client.name. , and so I give the context.Savechanges()
– Gabriel Heguedusch