Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

246
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda