I have a table with 6400 rows. This is a parent-children table, it has a foreign key to it self (a self-association reference in EF).
For this project, all tree must be loaded (load data when node is expanded is not a solution for me)
I have tried to load all nodes/tree at a time, but it exceed maximun items: “The InnerException message was ‘Maximum number of items that can be serialized or deserialized in an object graph is ‘65536’.”
Then I have tried to load data recursively, but maximun simultanius connections are maded (http://msdn.microsoft.com/en-us/library/cc304129%28VS.85%29.aspx). This is because loadoperation is asyncronous and recursion runs un parallel way.
Finaly I have write this code to load the data, it works (slowly) but I think that this is dirty solution:
Private Sub loadOperation_Completed(ByVal sender As Object, ByVal e As EventArgs)
Dim localloadOperation As LoadOperation(Of dimActivitats) = DirectCast(sender, LoadOperation(Of dimActivitats))
If Not localloadOperation.HasError Then
Dim llista = localloadOperation.Entities.ToList
If llista.Any AndAlso llista.First.idSubrogatPare Is Nothing Then
activitatsTree = llista
TreeViewTaula.DataContext = activitatsTree
End If
For Each i In llista
elementsWaitingForExpand.Push(i)
Next
End If
Dim take10 = 10
Dim IdsParentListOfElementsToProcessNow As New List(Of Integer)
While elementsWaitingForExpand.Count > 0 And take10 > 0
take10 -= 1
IdsParentListOfElementsToProcessNow.Add(elementsWaitingForExpand.Pop.idSubrogat)
End While
Dim q2 = CActx.GetDimActivitatsListChildQuery(IdsParentListOfElementsToProcessNow)
loadOperation = CActx.Load(Of dimActivitats)(q2)
AddHandler loadOperation.Completed, AddressOf loadOperation_Completed
ProgressBarTaula.Value = CActx.dimActivitats.Count
End Sub
I’m looking for some thing more elegant (semaphor? monitor? queue? ).
Here you can see a previeus solution that raise error due simultanius connections:
Private Sub loadOperation_Completed(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim localloadOperation As LoadOperation(Of dimActivitats) = DirectCast(sender, LoadOperation(Of dimActivitats))
If Not localloadOperation.HasError Then
Dim llista = localloadOperation.Entities.ToList
If llista.Any AndAlso llista.First.idSubrogatPare Is Nothing Then
activitatsTree = llista
TreeViewTaula.DataContext = activitatsTree
End If
TreeViewTaula.Dispatcher.BeginInvoke(New loadLlistaDelegate(AddressOf loadLlista), llista)
End If
Catch ex As Exception
End Try
End Sub
Private Delegate Sub loadLlistaDelegate(ByVal llista As List(Of dimActivitats))
Private Sub loadLlista(ByVal llista As List(Of dimActivitats))
For Each item In llista
For Each fill In item.dimActivitatsChildren
Dim q2 = CActx.GetDimActivitatsChildQuery(fill.idSubrogat)
Dim newloadOperation = CActx.Load(Of dimActivitats)(q2)
AddHandler newloadOperation.Completed, AddressOf loadOperation_Completed
Next
Next
End Sub
Do you have any idea to rewrite this code in more elegant way?
Do you have the maxItemsInObjectGraph setting in your service behavior in the web.config set to the maximum ? e.g