I'm trying to figure out how to create the LINQ-to-SQL for the following SQL and not having any luck. Any help would be appreciated. C# code for the response is prefered. Also, indexes other than PKey not shown for brevity.
Table Schema:
CREATE TABLE [dbo].[FileHashes](
[ID] [uniqueidentifier] NOT NULL,
[FileName] [nvarchar](255) NULL,
[FileSize] [bigint] NULL,
[FileDirectory] [nvarchar](255) NULL,
[SHA-1] [nchar](40) NULL,
[MD5] [nchar](32) NULL,
[CRC32] [nchar](8) NULL,
CONSTRAINT [PK_FileHashes] PRIMARY KEY CLUSTERED
(
[ID] ASC
)) ON {PRIMARY]
T-SQL:
select COUNT(ID) as DupCount, FileName from FileHashes
group by [SHA-1], FileName, FileSize
having COUNT(ID) > 1
order by DupCount desc, FileSize desc
I'm getting closer with this, but still not there yet:
from f in FileHashes
group f by new { f.SHA_1, f.FileName, f.FileSize } into g
orderby g.Key.FileSize descending
where g.Count() > 1
select new { g.Key.SHA_1, g.Key.FileName, g.Key.FileSize }
Thanks in advance, --Ed