entity-framework-core - 使用 Postgresql 在 EFCore 中按年龄过滤 - 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);
}
推荐阅读
- python - Alpha Vantage:遍历股票列表以获取技术指标
- google-apps-script - 使用 getNotes 设置值
- html - CSS 间距错误,内容超出容器
- python - 由于 UnicodeDecodeError,Anaconda 无法启动
- openoffice.org - 寻找 OpenOffice 基础 SQL 参考
- angular - 使用 Angular 8 将 http.get observable 转换为字符串的最简单示例
- google-sheets - 我想结合两个公式来做一个或另一个公式
- aframe - A-Frame Super Hands 旋转抓取的物体
- typescript - 引用项目中未使用的命名空间
- salt-stack - Saltstack/Jinja:如何从字符串列表中删除 u' 前缀