I am facing transaction related issues such as
the transaction operation cannot be performed because there are pending requests
or
New transaction is not allowed because there are other threads running in the session.
While I investigated for this error over internet I could see many blogs pointing towards using ToList() in for loops etc.
My question is I have too frequently used FirstOrDefault() in my project, should we always use .ToList() before doing FirstOrDefault(), or it doesn’t make any difference?
.ToList()method takes the query result in the memory so you no longer requires active connection with database for that.If you have large memory avilable then you can go for.ToList()You must be facing this issue for nested database calls i.e in loops