Suppose I have a table called Population that stores some demographic data. In T-SQL, to get the number of people over 50, I can do something like this:
SELECT COUNT(*) FROM POPULATION WHERE AGE > 50
I thought the following linq statement would work, but it just returns zero, and I don't understand why.
var count = _context.Population.Count(x => x.Age > 50);
To really get an account, I need to do one of the following:
var count = _context.Populaton.Where(x => x.Age > 50).Count(); var count = _context.Population.Select(x => x.Age > 50).Count();
Why are the scripts above?
Xaisoft
source share