.FirstOrDefault
This command is similar to the SingleOrDefault function, but when no records are found, it returns a null.
- Considered faster than .SingleOrDefault
- Similar commands: First(), .Take(1)
- This is similar to a TOP 1
Sample
1 | var dbPrograms = _context.Programs.FirstOrDefault(e => e.CategoryId == id && e.IsDeleted == false); |
from AFShin - instead of count, use .Any()
References