title: compare object int or dbnull.value linq
body: <p>I have a linq query:</p>
  
  <p><code>var capacityQuery = from Info in mySQLDataTable.AsEnumerable()
                       where Info.Field&lt;object&gt;("location") == Location.ID
                       orderby Info.Field&lt;DateTime&gt;("date")</code></p>
  
  <p>The line "where Info.Field("location") == Location.ID" is where I am having problems</p>
  
  <p>My Question is.  How do I do a comparison in the where statement that might be either a DBNull.Value or an int value on either side</p>
  
  <p>Below is for reference:</p>
  
  <p>Location is a custom class.  The ID returns an object.</p>
  
  <pre><code>    private int? addressID;
  
      public object ID {
          get
          {
              if (addressID == null)
                  return DBNull.Value;
              else
                  return addressID;
          }
      }
  </code></pre>
  
  <p>The reason it has to be DBNull is because it is coming from a database.  The "table" is also being filled in from a database.</p>
  
  <p>I know == in this case is wrong because its comparing the references which is obviously false.</p>
  
  <p>I know object.equal(var1, var2) should work but it doesnt which im guessing is because they are 2 different objects.</p>
  
  <p>The values could be an int or DBNull both on the table side and the class side.</p>
  
  <p>This is in a foreach loop so I use the same query where Location has an int value or when it has a DBNull value.</p>
  
  <p>Again My Question is.  How do I do a comparison in the where statement that might be either a DBNull.Value or an int value on either side</p>