Operator ‘==’ incompatible with operand types ‘Int32′ and ‘Object’

February 5, 2009 by: B.Harding

I had this error pop up on me recently.

Operator ‘==’ incompatible with operand types ‘Int32′ and ‘Object’

I had an good grasp on why but the stack track would not tell me where!

The issue is that a null object was being used in a where clause somewhere. Linq translated the null as “” and could not be compared the the ID field which is an int.

My solution was to simply check each key and cancel the action if there is a null value.

Since I couldn’t tell which Linq Data source was crashing I wired up on selecting events for them ALL and put the following code in:

foreach (KeyValuePair<string, object> kvp in e.WhereParameters)
{

if (kvp.Value == null){

e.Cancel = true;

return;

}

}

Problem solved.

Comments

5 Responses to “Operator ‘==’ incompatible with operand types ‘Int32′ and ‘Object’”
  1. Buster Hassell says:

    RSS feed is not working in chrome, Kindly fix it.

  2. Ronny Aden says:

    I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favorites web page list and will be checking back soon. Please check out my site as well and let me know what you think.

  3. Luci Nop says:

    This is a outstanding write-up, I found your website researching bing for a similar content and came to this. I couldnt discover to much alternative info on this posting, so it was nice to find this one. I will likely be returning to check out some other articles that you have another time.

  4. B.Harding says:

    Chrome doesn’t have a feed reader. Either use a plug-in or view it in a different browser.
    An RSS feed is just a link. The reader does the work.

  5. Walter Emert says:

    very nice post dude! great website… will be back soon!

Leave a Reply

*