I have a linq query:
var capacityQuery = from Info in mySQLDataTable.AsEnumerable()
where Info.Field<object>("location") == Location.ID
orderby Info.Field<DateTime>("date")
The line "where Info.Field("location") == Location.ID" is where I am having problems
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
Below is for reference:
Location is a custom class. The ID returns an object.
private int? addressID;
public object ID {
get
{
if (addressID == null)
return DBNull.Value;
else
return addressID;
}
}
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.
I know == in this case is wrong because its comparing the references which is obviously false.
I know object.equal(var1, var2) should work but it doesnt which im guessing is because they are 2 different objects.
The values could be an int or DBNull both on the table side and the class side.
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.
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