我在表格中有以下数据作为样本
我想在Entity框架语法查询中编写以存档以下SQL语法
SELECT a.* FROM tblDocMaps a inner join tblDoc b
on a.CURRENTDOCID = b.CURRENTDOCID
where b.FORMONTH IN(
SELECT DISTINCT TOP 2 aa.FORMONTH
FROM tblDoc aa inner join tblDocMaps bb
on aa.CURRENTDOCID = bb.CURRENTDOCID
WHERE (aa.FORMONTH < GETDATE())
AND (bb.INSTID=50)
ORDER BY aa.FORMONTH DESC
)
and a.INSTID=50
我怎么能写它来得到我想要的结果?我想从tblDocMaps中检索过去2个月的所有记录,其中tblDoc中定义了日期。
答案 0 :(得分:0)
var filteredMaps = tblDocMaps.Where(map => INSTID == 50);
filteredMaps.Where(map => filteredMaps.Where(map => map.tblDoc.FORMONTH < DateTime.Now)
.Select(map => map.tblDoc.FORMONTH)
.Distinct()
.OrderByDescending()
.Take(2)
.Contains(map.tblDoc.FORMONTH));