c# - LINQ - 不返回与 SQL Server 相同的值

标签 c# .net sql linq entity-framework

我有一个非常奇怪的问题。

我有这个查询:

var systemAppEntityViewModelFieldCustom_SecurityByUserList = (from t in coreEntityModel.SystemAppEntityViewModelFieldCustom_SecurityByUser
                where (t.SystemAppUserID == CurrentSystemAppUser.SystemAppUserID)
                    && (t.SystemCultureID == CurrentSystemAppUser.SystemCultureID)
                select t).ToList();

为“CustomFilterID”字段生成这些值:

enter image description here

如您所见,所有 4 个项目的“CustomFilterID”= 1,但是当我检查 SQLProfiler 并在 SQLServer 中运行结果查询时,我得到以下结果:

enter image description here

“CustomFilterID”的变体 = 1 AND 2。

知道为什么 LINQ 会生成“CustomFilterID”= 1 的所有 4 个项目吗?

最佳答案

发现问题了。我的 View 没有选择表的 PK 列,也没有将表的 PK 列添加到 的选择列表中查看,它产生了正确的结果。

关于c# - LINQ - 不返回与 SQL Server 相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16665253/

相关文章:

c# - 如何在 WPF 中为图像缩放变化设置动画?

c# - 如何生成总和为预定值的 N 个随机值?

.net - 在 TFS 源代码管理中更改用户名后,工作区出现问题

.net - 如何同时迭代多个 IEnumerables

c# - 在 Entity Framework 中动态选择数据库

c# - .Net HTML 编辑器控件

c# - 在字典中存储多个逆变委托(delegate)

c# - 带有代码修复的 VS2015 诊断 - NuGet 或 VSIX 或两者?

sql - Power Pivot 查询中的动态参数

sql - 如何在 Delphi 中查找与特定格式匹配的 Access 数据库中所有表的列表