這裏是SQL語句:在EF中我正在查找重複項並執行自引用查詢,我該如何編寫此查詢?
SELECT f1.*
FROM [File] f1
where 1 < (select count(*) from [File] f2 where f1.FileName = f2.FileName)
order by f1.FileName
這是一個相當簡單的查詢在SQL做的,但我不知道怎麼做,在EF。我來回答最接近的是這個(給我的PK和計數),但我想完整文件記錄回:
from f1 in File
join f2 in File on f1.FileName equals f2.FileName
group f1 by f1.FileId into c
where c.Count() > 1
select new { FileId = c.Key, number = c.Count() }
謝謝!這看起來最合適。 LinqPad說它轉換爲: - 區域參數 DECLARE @@ p0 Int = 1 - EndRegion SELECT [t0]。[FileId],[t0]。[FileName],[t0]。[DirectoryDefaultStructureId],[ [ProjectId],[t0]。[AssetId],[t0]。[BusinessUnitId],[t0]。[UploadedOn],[t0]。[CreatorUserId] FROM [File] AS [t0] WHERE ( )選擇計數(*) 從[文件] AS [t1] WHERE [t0]。[文件名] = [t1]。[文件名] ))> @@ p0 –