Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6572213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:58:39+00:00 2026-05-25T14:58:39+00:00

I have the following datatable, which has Units information. The Units have a surface

  • 0

I have the following datatable, which has Units information. The Units have a surface in square meters.
However the units can be split into subunits, in the datatable there is a ParentUnitID to know if that unit is splitted or not.

I need to validate that the sum of the surface of the child units, is equal to the surface of the parent unit.

enter image description here

The current code is something like:

private void ValidateUnitsStep(WorkspaceCancelEventArgs e)
{
    //Get data from step
    GetUnitsData();
    UserControlUnits Units = GetSmartPartByType<UserControlUnits>();

    if (_unitDataSet.Unit.HasErrors)
    {
        e.Cancel = true;
    }

    DataRow[] rows = _unitDataSet.Unit.Select("ParentUnitId !=" + string.Empty);
            foreach(DataRow dr in rows)
    {

    }
}

I would like to do this with LINQ. Linq Complex Query

Edit:
Yes, thats also possible, up to 2 levels of childs only

Unit A (100 sqm)

-UnitA1 (70)

  -UnitA11 (20)

  -UnitA12 (20)

  -UnitA12 (30)

-UnitA2 (30)

  -UnitA21 (20)

  -UnitA22 (10)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:58:40+00:00Added an answer on May 25, 2026 at 2:58 pm

    A possible implementation using linq to DataSet

    (1 level of children, but I’m sure you can work out for 2 levels)

    // Group the records by parent ID (potentially null)
    var childrenByParentID = _unitDataSet.Unit.AsEnumerable().
                             ToLookup(child => child.Field<int?>("ParentUnitId"));
    
    // Parents = children with no parent
    var parentsByID = childrenByParentID[null].ToLookup(parent => parent.Field<int>("UnitID"));
    
    // Look for the first group which sum of surfaces is not the same as the parent's surface
    var invalidGroup = childrenByParentID.FirstOrDefault(group => 
    {
      bool invalid = false;  
    
      if (group.Key != null)
      {
        // Not the parents group
        var currentParent = parentsByID[group.Key]);
    
        var totalSurface = group.Sum(row => row.Field<int>("Surface"));
        invalid = (totalSurface != currentParent.Field<int>("Surface"));
      }
    
      return invalid;
    });
    
    if (invalidGroup != null)
    {
      // .. do something special
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a DataTable userwidget , which has the following columns: process_id, emp_num,
I have a DataTable which has the following structure. StartDate (Type DateTime) EndDate (Type
I have a DataTable which is bound to datagridview (Winforms)... I use the following
I have one DataTable which has four columns such as MileStoneID MileStoneName Percentage SeqNbr
I've got a DataTable which has a number of records. I've tried the following
Which of the following has the best performance? I have seen method two implemented
How to do following scenario: I have some DataTable which contains for example some
I have the following python code which pushes data to db: cursor.execute(INSERT INTO +
I have two DataTables which has the following rows. Table A: TaxID TaxName ------
I have the following code that serializes a DataTable to XML. StringWriter sw =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.