为什么此 LINQ 查询将值 1 分配给数据库中的 NULL 值?

发布于 2024-10-28 06:42:41 字数 1332 浏览 0 评论 0原文

ExamVersion 类有一个名为 SourceSafeVersionNumint? 属性

当我执行以下代码时:

var query = from examVersion in db.ExamVersions
            where examVersion.ExamVersionID == ExamVersionID
            select examVersion;

foreach (ExamVersion examVer in query.ToList())
{
    yield return examVer;
}

设置了 examVer.SourceSafeVersionNum1,即使它在数据库中为 NULL

当我在 SQL Server 中运行 LINQ 生成的 SQL 代码时,SourceSafeVersionNum 列值为 NULL (如我所料),但在 foreach 循环中 examVer .SourceSafeVersionNum1

我在代码中找不到分配默认值或任何类似逻辑的地方。

有什么想法为什么/在哪里将此值设置为 1 吗?

这是属性声明(由 .dbml 文件生成)

[Column(Storage="_SourceSafeVersionNum", DbType="Int", UpdateCheck=UpdateCheck.Never)]
public System.Nullable<int> SourceSafeVersionNum
{
    get
    {
        return this._SourceSafeVersionNum;
    }
    set
    {
        if ((this._SourceSafeVersionNum != value))
        {
            this.OnSourceSafeVersionNumChanging(value);
            this.SendPropertyChanging();
            this._SourceSafeVersionNum = value;
            this.SendPropertyChanged("SourceSafeVersionNum");
            this.OnSourceSafeVersionNumChanged();
        }
    }
}

The ExamVersion class has an int? property named SourceSafeVersionNum

When I execute the following code:

var query = from examVersion in db.ExamVersions
            where examVersion.ExamVersionID == ExamVersionID
            select examVersion;

foreach (ExamVersion examVer in query.ToList())
{
    yield return examVer;
}

examVer.SourceSafeVersionNum is set to 1 even though it is NULL in the database.

When I run the SQL code generated by LINQ in SQL Server, the SourceSafeVersionNum column value is NULL (as I'd expect) but in the foreach loop the examVer.SourceSafeVersionNum is 1.

I can't find anywhere in the code where a default value is assigned or any similar logic.

Any ideas why/where this value is being set to 1?

Here is the property declaration (generated by a .dbml file)

[Column(Storage="_SourceSafeVersionNum", DbType="Int", UpdateCheck=UpdateCheck.Never)]
public System.Nullable<int> SourceSafeVersionNum
{
    get
    {
        return this._SourceSafeVersionNum;
    }
    set
    {
        if ((this._SourceSafeVersionNum != value))
        {
            this.OnSourceSafeVersionNumChanging(value);
            this.SendPropertyChanging();
            this._SourceSafeVersionNum = value;
            this.SendPropertyChanged("SourceSafeVersionNum");
            this.OnSourceSafeVersionNumChanged();
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妳是的陽光 2024-11-04 06:42:41

您是否尝试过在属性的 set{} 方法中设置断点,以查看还有哪些内容可能会填充其值?您可能会抓住罪魁祸首,然后查看调用堆栈看看是谁。

Have you tried setting a breakpoint in the set{} method of the property to see what else might be populating its value? You might catch the culprit in the act, then look at the Call Stack to see who it is.

ˉ厌 2024-11-04 06:42:41

作为后续操作,发生了以下情况:

从数据库检索值的代码被调用两次,但通过两个不同的代码路径。分配值 1 的代码路径被调试器跳过,所以我没有看到它。

As a follow up to this, here is what happened:

The code that retrieved the value from the database was being called twice but through two different code paths. The code path that was assigning the value of 1 was being stepped over by the debugger so I didn't see it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文