Operator '==' cannot be applied to operands of type 'string' and 'System.Guid' in MVC5 [closed]

You can use one of this solutions

1) You can use ToString() as fast solution. This method is better from performance pointofview :

  (u=>string.Equals(u.UsserId.Tostring()),Config.Userid, StringComparer.OrdinalIgnoreCase))

2) You can parse Guid as another fast solution. This methods is not so good for performance as previous, but in the case of incorrect guid you will be informed about it with help of exception:

u=>
{
    var parsedGuid;
    return Guid.Parse(Config.Userid)==Config.Userid;
}

to avoid exceptions you can use:

u=>
{
    var parsedGuid;
    if(Guid.TryParse(Config.Userid,out parsedGuid))
        return parsedGuid u.UsserId.Tostring()==Config.Userid;
    else 
        return false;
}

3) Correct way. you should change your DB model to keep userId not in string but in Guid. In other words UserRight.UsserId should have type Guid

Leave a Comment