Is is possible to turn a dateOfBirth in a linq query to an age within the query so i can do a comparis开发者_开发问答on to an int?
Cheers in advanced
Truez
It would be tricky or expensive to calculate the exact age for each record. Assuming you're really wanting to say something like "find me everyone 18 or over" it would be a better idea to work out the date of birth of someone who is exactly 18 today, and find everyone with a date of birth less than or each to that:
DateTime latestAdultBirth = DateTime.Today.AddYears(-18);
var adults = people.Where(person => person.dateOfBirth < latestAdultBirth);
精彩评论