- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
//Set Parent ID for the rest of the Reports data sources
this.ReportDataSources.ToList().ForEach(rds => rds.Parent = reportDataSource);
为什么不能直接设置Parent ID?什么可以让 LINQ 阻止这样的操作
//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();
}
}
}
最佳答案
不幸的是,ParentId 和 Parent 之间存在口是心非;让他们不同意是一种痛苦,所以它不会让你那样做。不过,您可以只设置 id - 尤其是在插入时。
你可以试试:
obj.Parent = null;
obj.ParentId = newParentId;
那么他们就不会发生冲突。
关于c# - 从逻辑上讲,为什么不能更改对象的 ParentID,而我必须自己更改父对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4296019/
我想使用“SpeechSynthesizer”来朗读文本,但该文本包含一些 XML 标记。使用旧的 COM 对象,我使用了 S5Voice.Speak uString, SVSFDefault Or
我对 MIT OCW Python 第 3 课有疑问。 根据简单的数学计算,她使用的代码应该不会成功。 ## EXAMPLE: approximate cube root ##############
从 CSP193p 2015 第 15 讲开始,prepareForSegue 中的以下代码将弹出窗口的高度最小化为 iPad 上的两行标签和文本字段: let minimumSize =
我目前正在尝试完成 iTunes U 上的 Swift 类(class),我们正在构建一个计算器。我无法理解部分代码。 我在下面添加了我认为与文件相关的代码。 让我感到困惑的是:为什么 operati
无法理解 PHRASES 部分的代码。这是《Python 艰难之路》中的代码。那部分之后我很失落。有人可以解释一下吗? 书中没有对下面的代码进行任何解释。 import random from url
此问题来自 MIT Python 类(class) 6.00.1X,Lectrue 8。我尝试了两段略有不同的代码。两者都是为了计算每个学生的平均成绩。 第一个代码没有考虑到可能存在字母等级,第二个代
在第 6 讲 Stanford iOS9 2016 系列讲座中,程序中添加了一个名为 VCL.swift 的文件来演示 View Controller 生命周期。 我已经添加了文件,但是对于行 "pr
我是一名优秀的程序员,十分优秀!