c# - 将 Sql all 运算符转换为 linq
问题描述
我需要从应该从另一个表输出中排除的表中检索详细信息。
以下查询成功检索了所需的输出:
select * from "table1"
where
"table1"."Id" != All (select "table2"."table1Id" from "table2" where (*conditions*))
AND *conditions*
我想在 linq 中进行相同的查询。我试过但无法实现它,因为我不知道如何在 linq 中使用all 。
from table1 in _db.table1
where
table1.Id != (from table2 in _db.table2 where (*conditions*))
&& *conditions*
select new class() {
Id = user.Id,
Name = user.Name
};
我已经尝试了很多参考,但对我不起作用。帮助我将此sql语句转换为linq。
解决方案
也许使用包含:
from table1 in _context.table1
where
!(from table2 in _context.table2 where (*conditions*) select table2.table1Id).Contains(table1.Id)
&& *conditions*
select new class() {
Id = user.Id,
Name = user.Name
};
推荐阅读
- ip-address - 如何使用 xip?
- flutter - “目前配置的 Flutter SDK 不知道是否完全支持。请更新你的 SDK 并重启 IntelliJ”
- matlab - 如何将此 MATLAB 脚本转换为 SCILAB?
- xml - 使用 XPath 从 Postgres XML 列中提取和格式化表
- javascript - 使用ajax实现时如何在数据表中添加页面长度
- python-3.x - 重新启动时使用 Python 3.9 和 Django 3.1.3 服务器崩溃
- swift - 如何使用 Alamofire 处理两种不同的 JSON 响应
- svg - 如何理解以下 SVG 代码?
- javascript - 如何让我的代码每个问题只显示一张图片
- python - 为 pytorch 安装预训练模型时出错