Linq to SQL 在 where 子句中使用 COALESCE 进行查询
Linq to SQL query with COALESCE in where clause
我正在尝试将以下 sql 查询转换为 linq 到 sql(对于 entity framework)
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
let x = d.UploadStatus == 0 //<--- COALESCE
from d in c.DefaultIfEmpty()
where x == true).ToList();
return query.ToList();
试试这个:
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();
我正在尝试将以下 sql 查询转换为 linq 到 sql(对于 entity framework)
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
let x = d.UploadStatus == 0 //<--- COALESCE
from d in c.DefaultIfEmpty()
where x == true).ToList();
return query.ToList();
试试这个:
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();