【发布时间】:2014-03-21 23:52:33
【问题描述】:
我有一个 linq 语句,它应该产生一个通用的左外连接(特别是空值),但它产生了一个奇怪的 sql,它也使用 count(*)
这是 linq:
(from ccc in cDataContext.CategoryCountryCategoryTypeMappings
join cl in currentLogs on ccc.CategoryCountryCategoryTypeMappingID equals
cl.CategoryCountryCategoryTypeMappingID
into final
select final);
当前日志如下所示:
(from dll in cDataContext.DownloadLogs
where dll.DTS.Hour == DateTime.Now.Hour && dll.DTS.Date== DateTime.Now.Date
select dll)
输出的sql变成:
SELECT [t1].[LogId], [t1].[CategoryCountryCategoryTypeMappingID], [t1].[CaptureTime], [t1].[Response], [t1].[DTS], [t1].[DLID], (
SELECT COUNT(*)
FROM clients.[dbo].[DownloadLog] AS [t2]
WHERE ([t0].[CategoryCountryCategoryTypeMappingID] = [t2].[CategoryCountryCategoryTypeMappingID])
) AS [value]
FROM clients.[Store].[CategoryCountryCategoryTypeMappings] AS [t0]
LEFT OUTER JOIN clients.[dbo].[DownloadLog] AS [t1] ON ([t0].[CategoryCountryCategoryTypeMappingID] = [t1].[CategoryCountryCategoryTypeMappingID])
ORDER BY [t0].[CategoryCountryCategoryTypeMappingID], [t1].[LogId]
我在寻找什么:
SELECT * FROM
clients.[Store].[CategoryCountryCategoryTypeMappings] AS [t0]
LEFT INNER JOIN clients.[dbo].[DownloadLog] AS [t1]
ON ([t0].[CategoryCountryCategoryTypeMappingID] = [t1].[CategoryCountryCategoryTypeMappingID])
如何生成所需的 sql?
【问题讨论】:
标签: c# sql sql-server linq