.net - How to convert the below 2 foreach nested loops to linq query? -
How to change the 2 foreach nested loop under the LINQ query? It takes about 10 seconds to execute this loop, which contains approximately 610 items. Apart from this, can any update be made in the lines of code given below so that the performance can be improved and slightly improved and the performance time can be reduced?
Code:
Forcha (Virus Map in InformationMap) {var testItem = map.TestItem; Var testInViews = TestviewMaps; Var testWorkbenchItem = map.TestWorkbenchItem; String TestLinkType = string.Empty; WorkItemLinkCollection testLinkedWorkItems = testItem.WorkItemLinkHistory; If (affiliates! = Null & amp; link worksite.Count & gt; 0) TestLinkType = Linked WorkItem [0] .LinkTypeEnd.LinkType.ReferenceName; Else if (testItem! = Null) TestLinkType = testItem.Store.WorkItemLinkTypes.LinkTypeEnds ["Parent"] LinkType.ReferenceName; Foreach (var testViewMap in testInViews) {if (! String.IsNullOrEmpty (TestLinkType)) {var testLinkName = TestLinkType; Var testchildType = testViewMap.ChildType; ITestLinkItem testItm = Factory.bildlist (testLinkName, testWorkbenchItem, testWorkbenchItem); Lock (testadapter) {TestAddparents.Add (testItm); } break; To answer the actual question (as per comments) - how to do But there are some things that I have seen:
- If you have a position in your loop Which never changes
(if !! String.IsNullOrEmpty (TestLinkType)) = & gt; Take it out - If you only run through a loop, then get the first item, due to having a loop in the first place.
New code like this:
foreach (var map in info map) {var testItem = map.TestItem; Var testInViews = TestviewMaps; Var testWorkbenchItem = map.TestWorkbenchItem; String TestLinkType = string.Empty; WorkItemLinkCollection testLinkedWorkItems = testItem.WorkItemLinkHistory; If (affiliates! = Null & amp; link worksite.Count & gt; 0) TestLinkType = Linked WorkItem [0] .LinkTypeEnd.LinkType.ReferenceName; Else if (testItem! = Null) TestLinkType = testItem.Store.WorkItemLinkTypes.LinkTypeEnds ["Parent"] LinkType.ReferenceName; If (! String.IsNullOrEmpty (TestLinkType)) {var testViewMap = testInViews.FirstOrDefault (); If (testViewMap! = Null) {var testLinkName = TestLinkType; Var testchildType = testViewMap.ChildType; ITestLinkItem testItm = Factory.bildlist (testLinkName, testWorkbenchItem, testWorkbenchItem); Lock (testadapter) {TestAddparents.Add (testItm); }}}} The real question is, where is the time lost, how much time it takes to get value from gates, whether you are calling any database or external call Are the processes that take long? In that case, you should retrieve as much data as possible at a time and cache it.
Comments
Post a Comment