0
votes

Is it possible to translate this following Postgresql query to EFCore?

SELECT "applic"."age" FROM (
   SELECT EXTRACT(YEAR FROM age(birthdate)) :: int AS "age" FROM public.applicant
) AS "applic"
WHERE "applic"."age" < 50;

I've looked into the documents but I can't find anything helpful.

1
A good start would be to try something and show us what you did and where how it didn't succeed (if it didn't). Only then can we see where specifically you need help.Gert Arnold
@GertArnold I posted a solution that worked.Hussain

1 Answers

0
votes

A solution that works:

var applicants = from s in this.RepositoryContext.Applicants select s;

if (query.AgeStart != null && query.AgeEnd != null)
{
    applicants = applicants.Where(c => (DateTime.Today.Year - c.BirthDate.Year) >= query.AgeStart && (DateTime.Today.Year - c.BirthDate.Year) < query.AgeEnd);
}