Update data with Entity Framework

Asked

Viewed 82 times

0

I have a problem that when I have this code below:

 public static String GravarNoBDFildes(List<Fildes> dados)
 {
         try
          {
             Console.WriteLine("Começando o processamento");
             var inseridos = new List<Fildes>();

             using (var fildesContext = new FildesContext())
             {
                    fildesContext.Configuration.AutoDetectChangesEnabled = true;
                    dados.ForEach(x => {   
                      var retorno = fildesContext.Fildess.Add(x);
                      inseridos.Add(retorno);
                    });                    

                    fildesContext.ChangeTracker.DetectChanges();
                    fildesContext.SaveChanges();
             }
             Console.WriteLine("Dados inseridos no Banco" + JsonConvert.SerializeObject(dados));
             return "Processamento foi concluido";
          }
 }

This error occurs when I start the console project:

"Processing failed with error: An error occurred while updating the Entries. See the Inner Exception for Details.".

What would that mistake be and how can I fix it please.

  • start by adding a catch(Exception ex){throw ex;} after your Try and debug your code line by line...

1 answer

0


Debug the code and take a look at Innerexception, inside it has a list of errors that were generated during the command there you will find what went wrong.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.