Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!