Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
Entity Framework not updating record

I have this method in the ParametersController class:

        public string SaveParameter(int id, string param, string val)
    {
        ProjectConfigurations config = new ProjectConfigurations();
        ProjectConfigurationsDAO dao = new ProjectConfigurationsDAO();

        config = dao.GetProjectConfigurationsByProjectAndParameter(id, param);
        
        config.Value = val;

        dao.Edit(config);

        return JsonConvert.SerializeObject(new { success = true, data = config });
        //return JsonConvert.SerializeObject(config);
    }

In my BaseDao class, I have this:

        public void Edit(T entity)
    {
        using (context = new Context())
        {
            context.Entry<T>(entity).State = EntityState.Modified;
            context.SaveChanges();
        }
    }

The record is not updated. I'm new to EF, what I'm I doing wrong?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

never try to create any generic repository since they are uselless. Try this

    public string SaveParameter(int id, string param, string val)
    {
        using (context = new Context())
        {
         var existedConfig=conext.Set<Config>.FirstOrDefault(i=> i.Id==id);
         existedConfig.Value=val;
          context.Entry<Config>(existedConfig).State = EntityState.Modified;
         context.SaveChanges();
         return JsonConvert.SerializeObject(new { success = true, data = config });
        }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda