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 )
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.
All comments are welcome and I will mark a solution any approach better than mine.