I saw this error, "Error: read ECONNRESET", on Postman's Console after changing my controller to insert data into the database via _context.AddRange()
. Previously, I added data via _context.Entity.Add()
and it was fine.
I changed the insertion method to be able to add a Lista (list) entity to the database while also inserting a list of n Pessoa (person) entities and n relations (list x person) to the database.
The inserts were all successfully made, although Postman still "Could not get any response".
Any idea why this is happening?
public async Task<IActionResult> PostListas(ListaFileInput input)
{
...
Listas lista = new Listas
{
OwnerId = userId,
Lista = input.Lista
};
...
List<Pessoas> pessoas = csv.GetRecords<Pessoas>().ToList();
foreach (Pessoas pessoa in pessoas)
{
pessoa.OwnerId = userId;
_context.AddRange(new ListasXPessoas() { Lista = lista, Pessoa = pessoa });
}
await _context.SaveChangesAsync();
return CreatedAtAction("GetListas", new { id = lista.ListaId }, lista);
ECONNRESET is a good indicator that some exception was thrown after execution left the controller. Examining the output window, I saw that the exception was:
Self referencing loop detected
I then found out that it was caused by the serialization to JSON of the returning object.
Ultimately, it was solved by adding the following code to ignore the loop verification:
services.AddMvc().AddJsonOptions(opt =>
opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With