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 7278013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:49:04+00:00 2026-05-28T22:49:04+00:00

This is the scenario: 2 Entities: tree and another tree id idParent someValue 1

  • 0

This is the scenario:

2 Entities: tree and another

            tree

id    idParent     someValue
1     NULL         ALL
2     1            Child1.1
3     2            Child2.1
4*    2            child...
5     4            child...
6*    1            child...
7     1            child1.3
8     1            child...
9     8            child1.4.1
...

           another

id    idTree      SomeValue
1     4*          bind 1
2     6*          bind 2

Graphicaly:

       tree
1
   2
      3
      4*      --> binded to 1
         5
   6*         --> binded to 2
   7
   8
      9

That I looking for is: How to select all leaf tree items that don’t has an ancestor binded to another. That is: 3, 7, 9

            tree

id    idParent     someValue
3     2            Child2.1
7     1            child1.3
9     8            child1.4.1

That I have tried

I split problem in small issues: getting all leaf items then look recursively to test is a ancestor is binded, an so on. But I get errors time outs or poor performance because I have 25k tree items and I don’t know how to get query with out temporary structures like lists.

I need a fresh approach for this issue. All comments are wellcome.

My Code (running … slow because recursion):

 Private Sub busca_no_assignats(
      ByRef l As List(Of Integer), 
      ByRef items As Object, 
      ByVal limit As Integer)
            If l.Count > limit Then
                Exit Sub
            End If
            For Each cu In items
                If cu.childrenItems.Count > 0 Then
                    If cu.others.Count = 0 Then
                        busca_no_assignats(l, cu.childrenItems, limit)
                    End If
                Else
                    If cu.others.Count = 0 Then
                        l.Add(cu.idItem)
                    End If
                End If
            Next
        End Sub


 Private Sub items_pendents_assignar_a_activitat_PreprocessQuery(
     ByRef query As System.Linq.IQueryable(Of LightSwitchApplication.tree))

     Dim l As New List(Of Integer)
     busca_no_assignats(l, Me.DataWorkspace.CAnaliticaData.tree_root_items, 100)

     query = From u In query
                    Where l.Contains(u.IdUnitat)

        End Sub
 End Class

(yes is EF through lightswitch )

  • 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-28T22:49:04+00:00Added an answer on May 28, 2026 at 10:49 pm

    Ok,

    I don’t expect for a solution because it is a little hard question.

    I post my final code. Performance is enough in production environment.

    Private Sub busca_no_assignats(
                ByRef l As List(Of Integer), 
                ByRef unitats As Object, 
                ByVal limit As Integer)
        If l.Count > limit Then
            Exit Sub
        End If
        For Each cu In unitats
            If l.Count < limit AndAlso cu.others.Count = 0 Then
                If cu.childrenItems.Count = 0 Then
                    If cu.others.Count = 0 Then
                        l.Add(cu.idItem)
                    End If
                Else
                    busca_no_assignats(l, cu.childrenItems, limit)
                End If
            End If
        Next
    End Sub
    

    All comments are welcome and I will mark a solution any approach better than mine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The scenario is: How can an Account give ratings to another account? This results
This scenario comes up often, now that I use LinkToSql and the classes it
Consider this scenario: I've an XML file called person.xml with the following data in
Consider this scenario. I have my own website, that I use as my identifier,
Consider this scenario. I have an object, lets call it.... Foo. Foo raises a
Is this scenario even possible? class Base { int someBaseMemer; }; template<class T> class
Imagine this scenario: You have a desktop and a laptop. The desktop has a
How would you test this scenario? I've just started looking into NHibernate and having
I have this scenario where I need data integrity in the physical database. For
we have this scenario: A server which contains needed data and client component which

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.