Bad performance
vladkolodka opened this issue · comments
Vladyslav commented
JournalWebApi/DJournalWebApi/Controllers/ImportController.cs
Lines 31 to 58 in c2fce42
data.ForEach(gr => | |
{ | |
Group t = _context.Groups.FirstOrDefault(gr1 => gr1.OldName == gr.oldname || gr1.NewName == gr.newname); | |
bool exist = true; | |
if (t == null) | |
{ | |
t = new Group() | |
{ | |
OldName = gr.oldname, | |
NewName = gr.newname, | |
}; | |
exist = false; | |
} | |
t.Students = gr.students.Select(st => | |
{ | |
if (_context.Students.FirstOrDefault(st1 => st1.Number == st.number) is Student s) | |
{ | |
return s; | |
} | |
return new Student | |
{ | |
Name = st.name, | |
Number = st.number | |
}; | |
}).ToList(); | |
if (!exist) _context.Groups.Add(t); | |
_context.SaveChanges(); |
Кол-во запросов к базе стремиться к бесконечности.