locked
"Operator '=' incompatible with operand types 'Guid' and 'Guid'"

    Question

  • I'm getting a weird exception, "Operator '=' incompatible with operand types 'Guid' and 'Guid'" on a dynamic query.

     

     

    IQueryable query = someIList.AsQueryable().Where("ID = @0", someID).Select("it");

     

    Any idea what may cause this?

    Friday, January 18, 2008 1:27 PM

Answers

  • Alternative workaround that allows the original query (Guid = Guid):

     

    Dynamic.cs - System.Linq.Dynamic.ExpressionParser - ParseComparison, line 712 changed from:

     

                    if (isEquality && !left.Type.IsValueType && !right.Type.IsValueType) {

     

    ...to:

     

                    if (isEquality && ((!left.Type.IsValueType && !right.Type.IsValueType) || (left.Type == typeof(Guid) && right.Type == typeof(Guid))) ) {

     

     

    Not sure if it is the right fix but it works.

     

    And I have to repeat: the lack of code comments is disturbing me.

    Thursday, January 24, 2008 6:59 AM

All replies


  • This query looks little bit strange to me. Do you have any more information about the list and what are you trying to accomplish?

    Petar
    Friday, January 18, 2008 5:02 PM
  • I'm trying to synchronize an entityset with a list. The entity type is not known at compile time, so I pass it as IList to the sync function.

     

    The existingSet param is an entity set I just got from the db, updatedSet is a List that I want to sync it with so the same changes can be applied to the db.

     

    public static void SynchronizeMembers(this SomeDataContext dc, Type entityType, IList existingSet, IList updatedSet)

    {

      foreach (var existingEntity in existingSet)

      {

        try

        {

          //find corresponding record in edited list

          string whereClause = null;

          object[] pkMembers = GetPKMembers(dc, existingEntity, out whereClause);

          IQueryable matchingEntity = updatedSet.AsQueryable().Where(whereClause, pkMembers).Select("it");

          var updatedEntity = matchingEntity.ToList()[0];

     

          //remove from edited list

          updatedSet.Remove(updatedEntity);

         

          //sync with existing item

          CopyDataMembers(dc, updatedEntity, existingEntity);

        }

        catch (Exception ex)

        {

          //item was removed in the updated collection

          dc.GetTable(entityType).DeleteOnSubmit(existingEntity);

        }

      }

      //remaining entries in edited list are new. add for insert

      dc.GetTable(entityType).InsertAllOnSubmit(updatedSet);

    }

     

    Saturday, January 19, 2008 12:53 AM
  • Update:

     

    Guid someID = new Guid("{d70a35c5-d80e-4ac5-96a7-8bd61ea3f28c}");

    IQueryable query = someIList.AsQueryable().Where("ID == @0", someID).Select("it");

     

    ...fails with that exception.

     

    But:

     

    string someID = "{d70a35c5-d80e-4ac5-96a7-8bd61ea3f28c}";

    IQueryable query = someIList.AsQueryable().Where("ID.ToString() == @0", someID).Select("it");

     

    ...works fine.

     

    Looks like the FindMethod function called from System.Linq.Dynamic.ExpressionParser.CheckAndPromoteOperands knows about boolean, timespan, string, datetime, int32, int64, char, single, double, decimal, the nullable versions of the same, but not guid.

     

    Dear MSFT, can you add a guid equality comparator along with some code comments? Smile
    Monday, January 21, 2008 5:03 AM
  • Alternative workaround that allows the original query (Guid = Guid):

     

    Dynamic.cs - System.Linq.Dynamic.ExpressionParser - ParseComparison, line 712 changed from:

     

                    if (isEquality && !left.Type.IsValueType && !right.Type.IsValueType) {

     

    ...to:

     

                    if (isEquality && ((!left.Type.IsValueType && !right.Type.IsValueType) || (left.Type == typeof(Guid) && right.Type == typeof(Guid))) ) {

     

     

    Not sure if it is the right fix but it works.

     

    And I have to repeat: the lack of code comments is disturbing me.

    Thursday, January 24, 2008 6:59 AM