entity-framework - 在 where 子句中使用 COALESCE 的 Linq to SQL 查询
问题描述
我正在尝试将以下 sql 查询转换为 linq to sql(用于实体框架)
select A.*, B.* from TABLE1 A
left join TABLE2 B
on A.LocationLoadPositionId = B.FkLocationLoadPositionId
where COALESCE(B.UploadStatus,0) = 0
到目前为止,我已经做到了这一点:
var positions = (from a in dbContext.TABLE1 join b in dbContext.TABLE2
on a.LocationLoadPositionId equals b.FkLocationLoadPositionId into c from d in c.DefaultIfEmpty()
where d.UploadStatus == false select new { a, d }).ToList();
由于我的 where 条件,上面的 linq 查询似乎无法正常工作......我为上面的两个查询得到不同的结果集......我在这里错过了什么?......
解决方案
尝试这个:
var positions = (from a in dbContext.TABLE1 join b in dbContext.TABLE2
on a.LocationLoadPositionId equals b.FkLocationLoadPositionId into c from d in c.DefaultIfEmpty()
where d.UploadStatus == false || d == null select new { a, d }).ToList();
推荐阅读
- azure - 使用 Azure Function Cosmos DB Changefeed 触发器使用 NServiceBus 发布消息
- python - 启动 Python 子进程方法的进程无法访问 Windows FS 中的其他文件
- flutter - 在颤振中调用时获取空值检查运算符用于空值错误
- python - 如何修复 Networkx 中某些节点的位置?
- arrays - 猫鼬替换索引前的值
- android-studio - 如何在 textView Android 中显示数学符号
- javascript - JavaScript - 测试用户是否在浏览器上搜索了页面
- node.js - 如何动态更新 jsonb 列
- c# - 无法使用 .NET 标准库通过 TLS 连接到 IBM MQ
- wordpress - Wordpress 网站标题未从选项卡中删除