Increase c# list performance

The problem is not the length of the list but the number of SQL queries. If you have 160 elements you have at list 161 sql statements which seems to be very slow in your case (use a profiler to analyze). You can try to modify your linq query to join the required products with the users. I don’t know your data model, but it could be something like this:

var users = from u in dbContext.Users.Include(u => u.Product);

or

var products = from p in dbContext.Products.Include(p => p.User);

Eager loading instead of lazy loading.

Leave a Comment