• Home
  • About
  • Resume

Method ‘System.Object CompareObjectEqual(System.Object, System.Object, Boolean)’ has no supported translation to SQL. Solution to error

By , 10/01/2009 2:15 PM

I was running a basic LINQ 2 SQL statement:

From role In db.user_role _
Where role.USER_ID = Session("user_id") Select role

when I encountered following error message:

Method ‘System.Object CompareObjectEqual(System.Object, System.Object, Boolean)’ has no supported translation to SQL.

After a little research I found the solution.

Apparently parameters for LINQ 2 SQL statements have to match the type of property (db field) used in the query exactly, no implicit conversion/type inference is going on. In my case role.USER_ID is of a String type and Session variable is of an Object type. When I explicitly converted Session variable to string:

From role In db.user_role _
Where role.USER_ID = Session("user_id").ToString Select role

it worked. So to avoid this error make sure parameter for your query has the same type as property it is being compared to and use type conversion if needed.

3 Responses to “Method ‘System.Object CompareObjectEqual(System.Object, System.Object, Boolean)’ has no supported translation to SQL. Solution to error”

  1. IL says:

    Great tip, thanks! I had the same error and you saved me much headscratching!

  2. Ravi says:

    thanks a lot Yuriy!

    gr8 help..

  3. Dip says:

    Thanks for the help!!!

Leave a Reply

Panorama Theme by Themocracy