开发者

How to let a column accept null values as zero (0) in Self-Relation table

开发者 https://www.devze.com 2023-02-03 09:28 出处:网络
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 rem

How to let a column accept null values as zero (0) in Self-Relation table

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
    report开发者_JAVA百科DataSource.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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消