我在 LINQPad 中输入了以下 LINQ,并使用 dbcontext 连接到我的数据库 (SQL Server 2005)。
from j in Jobs
where j.dValuationDate.HasValue && j.dValuationDate.Value > EntityFunctions.AddDays(DateTime.Now, -7).Value &&
j.dValuationDate.Value < EntityFunctions.AddHours(DateTime.Now, -1).Value &&
j.bXMLServiceProviderID.HasValue && j.bXMLServiceProviderID.Value == 1 &&
!ValuationDelays.Any(x => x.iJobID == j.iJobID && x.iStatusID == 5)
select j.iJobID
Jobs 和 ValuationDelays 是我的数据库中由 iJobId 列链接的表。
LINQPad 生成的 SQL 是:
SELECT
[Extent1].[iDelayID] AS [iDelayID],
[Extent1].[iJobID] AS [iJobID],
[Extent1].[sReasonforDelay] AS [sReasonforDelay],
[Extent1].[dDateTime] AS [dDateTime],
[Extent1].[iStaffID] AS [iStaffID],
[Extent1].[iStatusID] AS [iStatusID],
[Extent1].[dSentDate] AS [dSentDate],
[Extent1].[yValExDelayReasonID] AS [yValExDelayReasonID],
[Extent1].[dDelayedUntilDate] AS [dDelayedUntilDate],
[Extent1].[dValuationDate] AS [dValuationDate],
[Extent1].[valexActionUpdateId] AS [valexActionUpdateId],
[Extent1].[valexAppointmentReasonId] AS [valexAppointmentReasonId]
FROM [dbo].[ValuationDelays] AS [Extent1]
请注意,没有 where 子句。我不明白为什么 LINQPad 会生成这样的查询。我究竟做错了什么?
当我在 VS 2010 中调试时,查询运行良好并以 C# 代码返回预期结果。