LINQ to xml query with performance issue

firewall

New Member
I have written this LINQ to xml query:\[code\]Dim xd1 As XDocument = XDocument.Load("C:\doc1.xml")Dim xd2 As XDocument = XDocument.Load("C:\doc2.xml")Dim xd3 As XDocument = XDocument.Load("C:\doc3.xml")Dim q = From a In xd1...<row>, b In xd2...<row>, c In xd3...<row> Where a.@Field1 = "pippo" AndAlso b.@Field2 = a.@RifField2 AndAlso c.@Field3 = a.@RifField3 Select b.@Field4, b.@Field5, c.@Field6Dim s As String = ""For Each a In q s &= a.Campo4 & " - " & a.Campo5 & " - " & a.Campo6 & vbCrLfNextTextBlock1.Text = s\[/code\]But this code takes about 5 seconds to be executed. Certainly I would changed the query, but going in debug I have seen that the rowDim q = From ...takes an istant to be executed, and every following line goes away very fast until the cycle "For Each" has finished the items to scroll and it has to exit. Then the execution has a stop for 5 seconds, then the cycle exit.I obtain the same delay if I write\[code\]Dim q = (From ... ).ToArrayor else if I writeDim i As Long = q.Count\[/code\]The most strange is that it takes so long time to see that the items list is finished and it must to exit from the cycle. A detail: the query q has only 8 items.Have you got some suggestion to solve my performance issue?Pileggi
 
Back
Top