record does not update with EF

0

I have a rather annoying problem on the screen, I change the value of the field, and when saved, does not generate the error, and also does not save. The flow follows, as if there were no problems this object is so

clientes.endereco

I implemented the method this way:

var db = contexto;
db.Entry(obj).State = EntityState.Modified;

In an earlier attempt, t.

var clienteAtualizar = (from c in db.Clientes.Include(c => c.Endereco)
                                             .Include(c => c.Endereco.Cidade)
                                             .Include(c => c.Endereco.Estado)
                       where c.ClienteId.Equals(obj.ClienteId)
                       select c).FirstOrDefault();

        clienteAtualizar.Celular = obj.Celular;
        clienteAtualizar.ClienteId = obj.ClienteId;
        clienteAtualizar.Cpf = obj.Cpf;
        clienteAtualizar.Email = obj.Email;
        clienteAtualizar.Endereco = obj.Endereco;
        clienteAtualizar.Endereco.EnderecoId = obj.Endereco.EnderecoId;
        clienteAtualizar.Endereco.CidadeId = obj.Endereco.CidadeId;
        clienteAtualizar.Endereco.Cidade = obj.Endereco.Cidade;
        clienteAtualizar.Endereco.Cidade.Estado = obj.Endereco.Cidade.Estado;
        clienteAtualizar.Endereco.Cidade.EstadoId = obj.Endereco.Cidade.EstadoId;
        clienteAtualizar.Endereco.EstadoId = obj.Endereco.EstadoId;
        clienteAtualizar.Endereco.Estado = obj.Endereco.Estado;
        clienteAtualizar.Nome = obj.Nome;
        clienteAtualizar.Rg = obj.Rg;
        clienteAtualizar.TelFixo = obj.TelFixo;

        var entry = db.Entry(clienteAtualizar);

        db.Entry(clienteAtualizar).State = EntityState.Modified;

but it doubled the registry in child classes.

Does anyone have an idea how to solve this?

    
asked by anonymous 22.11.2016 / 02:11

1 answer

0

contexto.SaveChanges(); was missing under db.Entry(obj).State = EntityState.Modified;

    
22.11.2016 / 04:48