如何让自关系表中的列接受空值为零 (0)

发布于 2024-10-11 09:18:13 字数 1233 浏览 3 评论 0原文

alt text

如图所示,我得到了一个父子关系,并且由于 < 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。

alt text

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短叹 2024-10-18 09:18:13

你不能让你的根元素成为它自己的父元素吗?每次想要递归地查找元素祖先(以避免无休止的循环)时,您都必须检查它,但我认为它对您来说效果很好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文