【问题标题】:LINQ - Not returning the same value as SQL ServerLINQ - 不返回与 SQL Server 相同的值
【发布时间】:2013-05-21 08:20:49
【问题描述】:

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

我有这个问题:

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

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

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

“CustomFilterID”= 1 AND 2 的变体。

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

【问题讨论】:

  • 哪个是正确的?
  • @FrancescoDeLisi SQL 结果。
  • 我在模型主键设置不正确时遇到了这个问题,请先检查。
  • 你能列出coreEntityModel.SystemAppEntityViewModelFieldCustom_SecurityByUser的值吗?看起来很奇怪。
  • 也许你需要刷新你的上下文?

标签: c# .net sql linq entity-framework


【解决方案1】:

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

【讨论】:

  • 这正是从视图中选择的“棘手”问题之一——即使您不想显示它,也需要包含基础表的 PK 以使 EF 与视图正常工作跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-24
  • 2018-11-28
  • 2018-08-07
  • 1970-01-01
  • 2010-12-22
相关资源
最近更新 更多