开发者

Bug in generated LINQ to SQL class?

I have two tables: Budgets and Consultants. There is a 1 to 0..1 relation between Budgets and Consultants: a Budget has a Consultant and a Consultant can have a Budget.

The code generated by Linq to Sql for the Consultant property of a Budget is as follows:

[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Consultant_Budget", Storage="_Consultant", ThisKey="Id", OtherKey="Id", IsForeignKey=true, DeleteOnNull=true, DeleteRule="CASCADE")]
public Consultant Consultant
{
    get
    {
        return this._Consultant.Entity;
    }
    set
    {
        Consultant previousValue = this._Consultant.Entity;
        if (((previousValue != value) 
                    || (this._Consultant.HasLoadedOrAssignedValue == false)))
        {
            this.SendPropertyChanging();
            if ((previousValue != null))
            {
                this._Consultant.Entity = null;
                previousValue.Budget = null;
            }
            this._Consultant.Entity = value;
            if ((value != null))
            {
                value.Budget = this;
                *this._Id = value.Id;*
            }
            开发者_StackOverflow社区else
            {
                *this._Id = default(int);*
            }
            this.SendPropertyChanged("Consultant");
        }
    }
}

This seems wrong to me: why does the code change the ID of a Budget (see lines in italic) if its Consultant property is set?

By the way: the tables have been built using Lightswitch.


Because Budget depends on the consultant, _Id will contain the ID of the Consultant. When you look into the database, Budget table will contain Id column with primary key constraint and foreign key constraint referencing table for Consultant.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜