Having to call ToList each time, just to get one element doesn't seem good. Try to find a better approach
You are bringing the whole table data each time, imagne having 1 million row, how would that perform?
It is recommended to use asynchronous operations to prevent long-term synchronous blocking operations from causing threads to be occupied, so that a small amount of requests may exhaust service thread resources, and then there is a 'Where' operator, which can replace subscripts, but in high-frequency environments Using complex Linq below may cause additional small heap traffic due to Func creation. Here's an introduction to async: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/ Here's an introduction to the where operator: https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.where?view=net-6.0
try FirstOrDefault
I need to get the element by serial number, not by Id
FirstOrDefault(x=>x.SerialNumber==num)
Обсуждают сегодня