加载一个大银光树视图(问题为silverlight大师!)

时间:2011-07-24 09:42:41

标签: silverlight-4.0 ria

我有一个6400行的表。这是一个父子表,它有一个自己的外键(EF中的自我关联引用)。

对于这个项目,必须加载所有树(扩展节点时加载数据对我来说不是解决方案)

我曾尝试一次加载所有节点/树,但它超过了最大项:“InnerException消息是'对象图中可以序列化或反序列化的最大项数是'65536'。”

然后我尝试递归加载数据,但最大化simultanius连接是maded(http://msdn.microsoft.com/en-us/library/cc304129%28VS.85%29.aspx)。这是因为loadoperation是异步的,并且递归以不平行的方式运行。

最后我已经编写了这段代码来加载数据,它可以(慢慢地)工作,但我认为这是一个肮脏的解决方案:

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

我正在寻找更优雅的东西(semaphor?monitor?队列?)。


在这里,您可以看到一个由于simultanius连接而引发错误的普通解决方案:

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

您是否有任何想法以更优雅的方式重写此代码?

1 个答案:

答案 0 :(得分:0)

您是否将web.config中服务行为中的maxItemsInObjectGraph设置设置为最大值?例如

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <!--The service behavior for the RIA Service-->
        <behavior name="RIAServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer **maxItemsInObjectGraph="2147483647"** />