How do I perform a case-insensitive compare of GUIDs with LINQ?

前端 未结 4 1840
野的像风
野的像风 2021-01-04 02:49

In the code below, I want to compare two GUIDs. The problem is I don\'t get any tasks returned because the GUIDS are different case (uppercase vs. lowercase). I need to perf

4条回答
  •  既然无缘
    2021-01-04 03:42

    An easy way to ignore case when doing a string comparison is just convert everything to lower (or upper) case before you compare it. So:

    var userTasks = dc.tasks.Where(t => t.user_id.ToString().ToLower() == userId.ToString().ToLower()).ToList();
    

    That being said, I agree with the other commenters that you should be using a native GUID comparison, not a string comparison.

提交回复
热议问题