This is a migrated thread and some comments may be shown as answers.

Org Chart Constraints error

5 Answers 25 Views
OrgChart
This is a migrated thread and some comments may be shown as answers.
Giacomo
Top achievements
Rank 1
Giacomo asked on 31 Dec 2018, 02:47 AM

Hi,

we're trying to build an org chart, but we're getting the "Unable to activate this constraint. Not all values have corresponding parent values." error.

This is the code:

  • aspx:
  • <%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="Prova.aspx.cs" Inherits="TelerikOrgChart.Prova" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
     
    <html>
        <head>
            <meta name="viewport" content="width=device-width" />
            <title>Prova</title>
        </head>
        <body>
            <form id="form1" runat="server">
                <telerik:RadScriptManager runat="server" ID="RadScriptManager1"></telerik:RadScriptManager>
                <telerik:RadOrgChart ID="RadOrgChart1" runat="server" Skin="Windows7" GroupColumnCount="1"></telerik:RadOrgChart>
                 
            </form>
        </body>
    </html>
  • aspx.cs:
  • using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Entity;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using OrgChartSice.Data;
     
    namespace TelerikOrgChart
    {
        public partial class Prova : System.Web.UI.Page
        {
            private DataTable teams;
            private DataTable employees;
            protected void Page_Load(object sender, EventArgs e)
            {
                OrgChartSiceDbContext orgChartSiceDbContext = new OrgChartSiceDbContext();
     
                var data = orgChartSiceDbContext.dbvw_HRZU_Organigramma_Azienda_Teste.ToList();
                var teamList = data
                    .Select(c => new { c.IDBOX, c.IDBOXFATHER, c.DSBOX })
                    .Distinct().ToList();
     
                var employeeList = data
                    .Select(c => new { c.IDSUBJECT, c.IDBOX, c.NOMINATIVO })
                    .Distinct().ToList();
     
                CreateTeams(teamList);
     
                CreateEmployees(employeeList);
     
                RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldID = "TeamID";
                RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldParentID = "ReportsTo";
                RadOrgChart1.RenderedFields.NodeFields.Add(new Telerik.Web.UI.OrgChartRenderedField() { DataField = "Team" });
                RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataSource = teams;
     
                RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldID = "EmployeeID";
                RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldNodeID = "TeamID";
                RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataTextField = "Name";
     
                RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataSource = employees;
                 
                RadOrgChart1.DataBind();
                 
            }
     
            private void CreateEmployees(IEnumerable<dynamic> data)
            {
                employees = new DataTable();
                employees.Columns.Add("EmployeeID");
                employees.Columns.Add("TeamID");
                employees.Columns.Add("Name");
                //employees.Columns.Add("ImageUrl");
                foreach (var item in data)
                    employees.Rows.Add(new string[] { item.IDSUBJECT, item.IDBOX, item.NOMINATIVO });
            }
     
            private void CreateTeams(IEnumerable<dynamic> data)
            {
                teams = new DataTable();
                teams.Columns.Add("TeamID");
                teams.Columns.Add("ReportsTo");
                teams.Columns["ReportsTo"].AllowDBNull = true;
                teams.Columns.Add("Team");
                foreach (var item in data)
                    teams.Rows.Add(new string[] { item.IDBOX, item.IDBOXFATHER == item.IDBOX ? null : item.IDBOXFATHER, item.DSBOX });
            }
        }
    }
  • teams table:
  • Team ID Reports To Team
    0000000520 NULL Consiglio di Amministrazione
    0000000521 0000000520 Amministrazione
    0000000522 0000000521 Contabilità
    0000000523 0000000521 Risorse Umane
    0000000524 0000000521 Legale
    0000000525 0000000522 Ciclo Attivo
    0000000526 0000000522 Ciclo Passivo
    0000000527 0000000522 Tesoreria
    0000000530 0000000521 Ufficio IT
    0000000541 0000000522 Fiscale
    0000000542 0000000523 Rilevazione Presenze
    0000000543 0000000523 Gestione Appalti
    0000000544 0000000521 Controllo Gestione
    0000000546 0000000520 Commerciale
    0000000547 0000000546 Gestione Acquisti
    0000000554 0000000544 Controllo Produzione e Commesse
    0000000558 0000000544 Programmazione Commesse
    0000000561 0000000523 Paghe e Contributi
    0000000562 0000000547 Viaggi
    0000000563 0000000546 Preventivi
    0000000564 0000000547 Acquisti Commerciali
    0000000566 0000000547 Acquisti Magazzino e Accettazione Merci e Attrezzature
    0000000571 0000000580 Magazzino Merci
    0000000572 0000000571 Ricezione Merci
    0000000573 0000000580 Magazzino Attrezzature
    0000000574 0000000571 Imballaggio
    0000000575 0000000571 Magazzino Costruzioni
    0000000576 0000000571 Magazzino Ferramenta
    0000000577 0000000546 Logistica
    0000000578 0000000577 Trasporti
    0000000579 0000000578 Trasporti Esterni
    0000000580 0000000577 Magazzino
    0000000581 0000000578 Trasporti Interni
    0000000582 0000000578 Trasporti e Magazzino Francia
    0000000583 0000000563 Preventivi Arredi
    0000000584 0000000563 Preventivi Costruzioni
    0000000585 0000000520 Tecnica
    0000000586 0000000585 Gestione Commesse
    0000000587 0000000586 PM Commesse Arredi
    0000000588 0000000586 PM Commesse Costruzioni
    0000000589 0000000586 Manutenzioni Commesse
    0000000590 0000000585 Cantieri
    0000000591 0000000590 Cantieri Costruzioni
    0000000592 0000000591 Gestione Cantieri Costruzioni
    0000000593 0000000592 Coordinamento Cantiere
    0000000594 0000000592 Contabilità
    0000000595 0000000591 Produzione Cantiere Costruzioni
    0000000596 0000000595 Carpenteria Edile
    0000000597 0000000595 Cartongessi
    0000000598 0000000595 Gessi
    0000000599 0000000595 Imbiancatura
    0000000600 0000000595 Muratura
    0000000601 0000000585 Produzione
    0000000605 0000000601 Produzione Arredi
    0000000606 0000000605 Produzione Carpenteria Leggera
    0000000607 0000000605 Produzione Acciai
    0000000608 0000000605 Produzione Falegnameria
    0000000609 0000000605 Produzione Finiture
    0000000610 0000000609 Decorazioni
    0000000611 0000000609 Verniciatura
    0000000612 0000000605 Produzione Marmi e Vetro
    0000000613 0000000605 Progettazione Prd Arredi
    0000000614 0000000613 Gestione Commesse di Produzione
    0000000615 0000000613 Progettazione di Produzione ACL
    0000000616 0000000613 Progettazione di Produzione LG
    0000000617 0000000601 Produzione Costruzioni
    0000000618 0000000617 Produzione Carpenteria Pesante
    0000000619 0000000585 Progettazione
    0000000620 0000000619 Progettazione Arredi
    0000000621 0000000620 Progettazione Carpenteria Leggera
    0000000622 0000000620 Progettazione Legno Acciaio
    0000000623 0000000619 Progettazione Costruzioni
    0000000624 0000000623 Progettazione Carpenteria Pesante
    0000000625 0000000623 Progettazione Edile
    0000000626 0000000520 Servizi Generali
    0000000627 0000000626 Servizi
    0000000628 0000000627 Centralino
    0000000629 0000000627 Manutenzione Immobili Impianti e Attrezzature
    0000000630 0000000629 Pulizie
    0000000631 0000000627 Ristorante Dopolavoro
    0000000632 0000000626 Sicurezza
    0000000633 0000000632 Sicurezza Cantieri e Stabilimento
    0000000635 0000000632 Formazione
    0000000636 0000000632 Ambiente
    0000000637 0000000595 Montaggi Carpenteria
    0000000638 0000000629 Gestione Impianti e Attrezzature
    0000000640 0000000588 Gestione Personale Cantieri Costruzione
    0000000641 0000000581 Trasporti Costruzioni
    0000000642 0000000581 Trasporti Arredi
    0000000644 0000000590 Cantieri Arredi
    0000000646 0000000645 Coordinamento Montaggio Arredi
    0000000647 0000000645 Montaggi Arredi
    0000000648 0000000627 Immagine e Comunicazione

This is the stack error:

System.Data.ConstraintCollection.AddForeignKeyConstraint(ForeignKeyConstraint constraint) +2097678
   System.Data.ConstraintCollection.Add(Constraint constraint, Boolean addUniqueWhenAddingForeign) +371
   System.Data.DataSetRelationCollection.AddCore(DataRelation relation) +929
   System.Data.DataRelationCollection.Add(DataRelation relation) +159
   System.Data.DataRelationCollection.Add(DataColumn parentColumn, DataColumn childColumn) +45
   Telerik.Web.UI.ControlDataBinder.BindToDataTable(DataTable table, String dataFieldID, String dataFieldParentID) +104
   Telerik.Web.UI.OrgChartNodeBinder.PerformDataBinding(IEnumerable data) +242
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +34
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   Telerik.Web.UI.OrgChartNodeBinder.SimpleBindingProcedure() +13
   Telerik.Web.UI.OrgChartNodeBinder.GroupEnabledBindingProcedure() +168
   Telerik.Web.UI.OrgChartNodeBinder.DataBind() +64
   Telerik.Web.UI.RadOrgChart.DataBind() +95
   TelerikOrgChart.Prova.Page_Load(Object sender, EventArgs e) in C:\MEGA\Projects\OrgChartSice\TelerikOrgChart\Prova.aspx.cs:55
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +95
   System.Web.UI.Control.LoadRecursive() +59
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678

5 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 02 Jan 2019, 10:42 AM
Hi Giacomo,

This error, coming from the .NET binding, indicates that there is an issue with the parent relationships. For example, the actual data object that is given the org chart does not have any nodes with a null parent ID (even though you have NULL in the database, it is possible that the .NET object has something like "NULL"). Another common issue is that there is a row whose ParentID does not exist in any row's ID field.

I am attaching here an example I made based on the provided code which seems to work fine for me. I advise that you compare to it and see what is the difference causing the issue. You could, for example trim the actual data to only a few rows and if the issue is gone, start expanding the used subset until the issue manifests, so you can see which row causes the problem and what it is.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Giacomo
Top achievements
Rank 1
answered on 02 Jan 2019, 02:08 PM

Hi Marin,

thanks for the reply and happy new year.

I found the problem, we have some child nodes ID that are less than their parent.

This is an example:

IDBOX     IDBOXFATHER    DSBOX

0000000564 0000000547 Acquisti Commerciali
0000000566 0000000547 Acquisti Magazzino e Accettazione Merci e Attrezzature
0000000571 0000000580 Magazzino Merci
0000000572 0000000571 Ricezione Merci
0000000573 0000000580 Magazzino Attrezzature
0000000574 0000000571 Imballaggio
0000000575 0000000571 Magazzino Costruzioni
0000000576 0000000571 Magazzino Ferramenta
0000000577 0000000546 Logistica
0000000578 0000000577 Trasporti
0000000579 0000000578 Trasporti Esterni
0000000580 0000000577 Magazzino

Is there a way to avoid this ordering problem without modify the database?

I have the same problem also ordering by ParentID (IDBOXFATHER)

0
Marin Bratanov
Telerik team
answered on 02 Jan 2019, 03:57 PM
Hello Giacomo,

It is good to hear we know the reason for the issue. I am sorry to say, however, that I am not aware of ways to avoid such an issue since it comes down to the .NET data binding logic and we can't influence that unless an entirely custom implementation is made, which does not seem likely considering that it already exists in the framework.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Giacomo
Top achievements
Rank 1
answered on 08 Jan 2019, 07:39 AM

Hello,

The field IDBOX in the view is a table used in many org charts, so we can't change them from the source.

I should order the view in a different way, or change the IDs in the view, but if someone change the org chart in the future is a problem.

Any ideas on how to solve this?

 

Thanks

 

0
Marin Bratanov
Telerik team
answered on 08 Jan 2019, 05:19 PM
Hi Giacomo,

The error comes from the .NET data binding logic and I simply cannot say what are the exact requirements or issues that one may face depending on the values. Usually the error means that data in the child data cannot find its parent. I do hope you will be able to find the data issue that is causing this and remove it.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
OrgChart
Asked by
Giacomo
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Giacomo
Top achievements
Rank 1
Share this question
or