2
//Set Parent ID for the rest of the Reports data sources
this.ReportDataSources.ToList().ForEach(rds => rds.Parent = reportDataSource);
爲什麼我不能直接設置父ID?什麼可以讓LINQ防止這樣的動作邏輯上,爲什麼不能改變對象的ParentID,而是我必須改變父母它自己?
//Set Parent ID for the rest of the Reports data sources
this.ReportDataSources.ToList().ForEach(rds => rds.ParentID = reportDataSource.ID);
異常這裏時拋出
[Column(Storage="_ParentID", DbType="Int")]
public System.Nullable<int> ParentID
{
get
{
return this._ParentID;
}
set
{
if ((this._ParentID != value))
{
if (this._Parent.HasLoadedOrAssignedValue)
{
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
}
this.OnParentIDChanging(value);
this.SendPropertyChanging();
this._ParentID = value;
this.SendPropertyChanged("ParentID");
this.OnParentIDChanged();
}
}
}
當然,我調試它,我發佈在代碼上的異常:拋出新的System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();每當ParentId改變時拋出。 – 2010-11-28 08:49:10