title: Linq to Objects performance and best implementation
body: <p>I work on a web application that modifies a XML document that is stored in a database. It is made to mimic exactly like any program does when you click the "preferences" option in the menu. The XML document is read by a local client application and any changes are reflected in the local client.</p>
  
  <p>My web app has 3 tiers I guess you would say with the aspx page being the "view", a service layer where I validate / process all user input, and a data layer where I update the XML document.</p>
  
  <p>For each page of settings, I had been recursively traversing all the controls on the page and if I came to one that I wanted to work on (checkbox, textbox, ...) I added it to a IList and then sent that IList to the service layer where I then had to pull the control out of the list so I could work on it.</p>
  
  <p>I noticed this seemed to be a bit slow so I profiled the page and basically the LINQ to Objects queries that I had been using tend to eat up a ton of time.</p>
  
  <pre><code>(CheckBox)lstControls.Where(x =&gt; x.ID == "some_id").SingleOrDefault();
  </code></pre>
  
  <p>I then switched to manually adding the controls on the page to a IList and then pulling them out in the service layer by indexer in the order they were put in.  This is fugly and completely dependent on you not screwing up the index of the control you are looking for.</p>
  
  <p>Finally, this breaks the rule of mixing elements from the view with the service layer or data layer.  I know I should be working with data only, but I am at a loss of how to efficiently do this.</p>
  
  <p>Each settings page has from one to thirty controls that need to be processed.  How do I get all the data from the controls to the service layer without sending the actual controls?</p>
  
  <p>Thanks for the help....</p>