使用 Postgresql - Npgsql 在 EFCore 中按年龄过滤

Filter by Age in EFCore using Postgresql - Npgsql

是否可以将以下 Postgresql 查询转换为 EFCore?

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

我查看了文档,但找不到任何有用的信息。

有效的解决方案:

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);
}