评估LINQ表达式后何时设置属性值? [英] When is the value of a property set after a LINQ expression is evaluated?

查看:95
本文介绍了评估LINQ表达式后何时设置属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linq对SQL Server执行查询后,何时设置对象的属性?

After Linq executes a query against SQL Server, when are the properties of a object set?

ExamVersion类的以下属性是由LINQ to SQL类(.dbml)文件生成的.

The following property of the ExamVersion class was generated by a LINQ to SQL Classes (.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();
        }
    }
}

执行此LINQ查询后:

After I execute this LINQ query:

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

return query.ToList();

LINQ在何时/何处设置SourceSafeVersionNum属性?

When/where does LINQ set the SourceSafeVersionNum property?

我在setter上放置了一个断点,但是在调试过程中从未调用过该断点.没有设置该值的构造函数.

I've placed a breakpoint on the setter but it is never called during debugging. There is no constructor which sets this value.

推荐答案

Linq to sql类是从核心对象继承的,并且取决于您是使用EF还是linq to sql使用代理类进行填充.

Linq to sql classes inherit from a core object and depending on if you're using EF or linq to sql use proxy classes to populate.

您是否尝试过将私有属性"_SourceSafeVersionNum"更改为具有get和set然后断点私有基础变量?公共设置程序用于您的应用程序设置变量时,以便它可以跟踪更改.如果在从数据库填充时使用了这些属性,则所有属性在加载时都会触发OnPropertyChanged.

Have you tried changing the private property "_SourceSafeVersionNum" to have a get and a set then breakpoint the private underlying variable? The public setters are intended for when your application sets the variable so it can track the change. If it used these when populating from the DB all your properties would fire OnPropertyChanged when they load.

这篇关于评估LINQ表达式后何时设置属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆