我已經爲此搜索了,但找不到任何明顯相關的東西,所以在這裏張貼一些見解。使用LINQ/EF4。這裏是代碼片段:LINQ到EF4查詢Where子句沒有按預期過濾
private const string JOB_FAILED = "Failed";
// other code..
var successfulJobs = context.Jobs.Where(x => x.Status != JOB_FAILED);
foreach (Job successfulJob in successfulJobs)
{
context.DeleteObject(successfulJob);
}
我期望成功的作業包含所有Job.Status!=「失敗」的作業。但是,當Job.Status等於「失敗」時,代碼witihn foreach {}會執行。我在這裏錯過了關於LINQ \ Lambda的基本知識嗎?
編輯:生成的SQL按要求,似乎沒問題。
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Parameters] AS [Parameters],
[Extent1].[Status] AS [Status],
[Extent1].[Created] AS [Created],
[Extent1].[Modified] AS [Modified]
FROM [bws].[JobRunner_Tasks] AS [Extent1]
WHERE N'Failed' <> [Extent1].[Status]
你可以發佈正在執行的SQL嗎?您可以使用SQL Server Profiler捕獲該數據。 – usr 2012-04-24 19:48:15
嘗試進行不區分大小寫的比較:'var successfulJobs = context.Jobs.Where(x => String.Compare(x.Status,JOB_FAILED,true)!= 0)' – sarghir 2012-04-24 20:09:38
按照您的建議嘗試,但我仍然得到同樣的問題 – 2012-04-24 21:56:26