Guid type and ( '>' greater than comparison) in LINQ to SQL

后端 未结 3 655
春和景丽
春和景丽 2021-01-18 22:24

Please, help me. I try compare two guid in .Where() query method. But I get compile error. Error 1 Operator \'>\' can not be applied to operands of type \"System.Guid\" and

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-18 22:42

    It doesn't make sense to apply greater than or less than to a Guid.

    0f8fad5b-d9cb-469f-a165-70867728950e and 7c9e6679-7425-40de-944b-e07fc1f90ae7

    Two Guids but which is greater? Do you drop the - and calculate the total of the HEX? or how about add the sums of the HEX between - ?

    It's just simply not done (though it could be)

    Apply logical == and != does however make sense though. The Guid struct does overload the == and != operators, so use them and you can also easily compare string values i.e.

    var isEqual = guid.ToString().Equals(otherGuid.ToString());

提交回复
热议问题