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