请告诉我如何在LINQ To SQL中转换此SQL查询?提前谢谢。
SELECT [Movies].[Name]
FROM
(
SELECT [Value]
FROM [Index]
WHERE ('WORD1' = [Word] and [MatchCount] = 1)
OR ([Word] = 'WORD2' AND [MatchCount] = 1)
GROUP BY [Value]
HAVING COUNT([Value]) = 2
) AS [Guids]
LEFT OUTER JOIN [Movies] ON [Movies].[Guid] = [Guids].[Value]
答案 0 :(得分:1)
在a previous question中,有人建议Linqer。
老实说,我自己从未使用过它,但我已广泛使用LinqPad。它做了相反的事情(以及将LINQ转换为lambda表达式),并且是我最喜欢的工具之一。
答案 1 :(得分:1)
这样的东西? (警告,以下代码未经测试!)
var q = from i in Index
where i.MatchCount == 1 &&
(i.Word == "WORD1" || i.Word == "WORD2")
group i by i.Value into g
where g.Count() == 2
from m in Movies.Where(x => x.Guid == g.Key).DefaultIfEmpty()
select m.Name;