如何让自关系表中的列接受空值为零 (0)
如图所示,我得到了一个父子关系
,并且由于 < code>ParentID 不接受空值(由于我的 UI 中存在一些限制,我无法更改为空标签),如何删除 ReportDataSources 之间的存在关系以便更改它们的父级(此处我想为其中之一设置parentId = 0)我该怎么做,因为我无法直接更改ParentID
并且设置Parent = null
无效
public void SetReportDataSourceAsMaster(ReportDataSource reportDataSource)
{
//Reset Master
this.ReportDataSources.ToList().ForEach(rds => rds.IsMaster = false);
//Set Master
reportDataSource.IsMaster = true;
//Set Parent ID for the rest of the Reports data sources
this.ReportDataSources.Where(rds => rds.ID != reportDataSource.ID).ToList().ForEach(rds =>
{
//Change Parent ID
rds.Parent = reportDataSource;
//Remove filttering data
rds.FilteringDataMembers.Clear();
//Remove Grouping Data
rds.GroupingDataMembers.Clear();
});
//Delete parent HERE THE EXCEPTION THROWN AFTER CALLING SUBMITCHANGES()
reportDataSource.Parent = null;
}
之后抛出异常调用SubmitChanges()
:
尝试删除 ReportDataSource 和 ReportDataSource 之间的关系。但是,关系的外键之一 (ReportDataSource.ParentID) 不能设置为 null。
As described in the image, I got a parent-Children relation
and since the ParentID
not accepting null values (and I can't change to nullabel due to some restriction in the UI I have), how can I remove an existence relation between ReportDataSources in order to change the parent for them (here i want to set the parentId for one of them = 0) how could i do that since i cant change the ParentID directly
and setting Parent = null
is not valid
public void SetReportDataSourceAsMaster(ReportDataSource reportDataSource)
{
//Reset Master
this.ReportDataSources.ToList().ForEach(rds => rds.IsMaster = false);
//Set Master
reportDataSource.IsMaster = true;
//Set Parent ID for the rest of the Reports data sources
this.ReportDataSources.Where(rds => rds.ID != reportDataSource.ID).ToList().ForEach(rds =>
{
//Change Parent ID
rds.Parent = reportDataSource;
//Remove filttering data
rds.FilteringDataMembers.Clear();
//Remove Grouping Data
rds.GroupingDataMembers.Clear();
});
//Delete parent HERE THE EXCEPTION THROWN AFTER CALLING SUBMITCHANGES()
reportDataSource.Parent = null;
}
Exception thrown after calling SubmitChanges()
:
An attempt was made to remove a relationship between a ReportDataSource and a ReportDataSource. However, one of the relationship's foreign keys (ReportDataSource.ParentID) cannot be set to null.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能让你的根元素成为它自己的父元素吗?每次想要递归地查找元素祖先(以避免无休止的循环)时,您都必须检查它,但我认为它对您来说效果很好。
Can't you make your root element be its own parent? You would have to check it each time you want to recursively find an element ancestor (to avoid unending loops), but I think it would work fine for you.