Linq Query keeps throwing "Unable to create a constant value of type System.Object....", Why?

Use == instead of Equals:

where t.CustID == custIdToQuery

If the types are incorrect you may find that this doesn't compile.


I had the same issue with a nullable int. Using == instead works nicely, but if you want to use .Equals, you can compare it to the value of the nullable variable, so

where t.CustID.Value.Equals(custIdToQuery)

I had the same issue when I was trying to do .Equals with a nullable decimal. Using == instead works nicely. I guess this is because it's not trying to match the exact "type" of decimal? to decimal.