In BooksList I have around 60k records and in Readers I have around 20 only.
Now, to populate the bridge table (many-to-many) I have to assign each BookList record at least 2 Readers.
It's done but on the loading of app for the first time, it takes around ~30 seconds.
Is it normal?
Is there any way to speed it up?
Note: this is the requirement and I have to do it this way means I have to seed the data on the first load but my concern is performance.
foreach (var n in BooksList) //60k records
{
int innerLoopCounter = 0;
foreach (var t in ReadersList) //only 20 registered readers
{
BooksReadersList.Add(new BooksReaders() { BooksID = n.BooksID, ReaderID = t.ReaderID });
innerLoopCounter++;
if (innerLoopCounter > 2) //should not be more than 2.
break;
}
}
BooksDbContext.BooksReaders.AddRange(BooksReadersList);
BooksDbContext.ChangeTracker.DetectChanges();
base.Seed(BooksDbContext);
The BooksReadersList is a list of type BookReaders which has 3 columns (ID, Book_ID, Reader_ID).
The BooksList is a list of type Books which as 2 columns (ID, BookTitle) and ReaderList is a list of type Readers which as 2 columns (ID, ReaderName).