title: Using Linq for comparison of two Datatables
body: <p>I am developing a C# ASP.NET web application.  I have data being pulled from two databases.  One is the database that holds all of our actual data, the second is to be used so that users of the site can save "favorites" and easily find this data later.  The databases have the following columns: </p>
  
  <p>Table1: </p>
  
  <pre>itemid, itemdept, itemdescription</pre>
  
  <p>Table2:</p>
  
  <pre>userid, itemid, itemdept, itemdescription</pre>
  
  <p>If the item is present in table2 (the user has already added it), I want to mark the item as removable if it comes up again in a search, and addable if it has is not yet in their favorites.</p>
  
  <p>I've got data from both pulled into datatables so I can compare them, but I feel that using a nested foreach loops will be too tedious as the query is set to return a max of 300 results. Also to do that, I have to put a bool value in one of the tables to mark that it was found, so this seems messy.  </p>
  
  <p>I have read up a little on Linq, but can't find anything exactly like this scenario.  Could I use Linq to accomplish such a thing?  Below is an (admittedly crude) image of the search results page that may help get a better grasp on this.  In the real deal, the Add and Remove links will be imagebuttons.</p>
  
  <p><img src="https://i.stack.imgur.com/dY5Vm.png" alt="SiteLayout"></p>