Stop select the database on each itterate

Published 7 months ago by mkdesign82

Hi,

I have a table with 700,000 records init with 20 column length, in part of my project I have a foreach which I should select one record from the table, for 400 iterates and 400 select, it took me 46sec to retrieve the 400 results. which is not good. guys do you have any idea to improve the speed and the time I use.

tykus
tykus
7 months ago (623,240 XP)

This is a use case for eager-loading if there is a relationship between the collection being iterated over and the select query being made.

It is difficult suggest anything further without more information about your specific case.

audiogram

Yes, the GOTO for avoiding the hell you're in is eager loading. Check out the docs on this for a very clear and concise explanation.

Please sign in or create an account to participate in this conversation.