简体   繁体   English

LINQ to EF4 Query Where子句未按预期进行过滤

[英]LINQ to EF4 Query Where clause not filtering as expected

I've googled for this but can't find anything obviously related, so posting here for some insight. 我已经为此进行了搜索,但找不到任何明显相关的内容,因此请在此处发布以获取一些见识。 Using LINQ / EF4. 使用LINQ / EF4。 Here's the code snippet: 这是代码片段:

 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);
                }

I would expect successfulJobs to contain all jobs where Job.Status != "Failed". 我希望successJobs包含Job.Status!=“ Failed”的所有作业。 However, the code witihn foreach{} executes when Job.Status DOES equal "Failed". 但是,当Job.Status等于“失败”时,将执行代码witihn foreach {}。 Am I missing something fundamental here about LINQ\\Lambda? 我是否在这里缺少有关LINQ \\ Lambda的基本知识?

EDIT: Generated SQL as requested, seems ok. 编辑:按要求生成的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]

hmmmm.... in any other language, I might suggest using 嗯....在任何其他语言下,我可能建议使用

x => !x.Status.equals(JOB_FAILED)

but I didn't think string comparison was that finicky in C# 但是我不认为字符串比较在C#中是如此挑剔

I would still say it's a case sensitive issue. 我仍然会说这是一个区分大小写的问题。 What does the query return if you run it directly in SQL? 如果直接在SQL中运行查询,查询返回什么? Can you maybe post a sample of the data in that table? 您能否在该表中发布数据样本? (Including "Failed" statuses) I know this isn't an answer but i can't add comments to the post yet (rep below 50). (包括“失败”状态)我知道这不是一个答案,但我还不能在帖子中添加评论(低于50的代表)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM