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 perform a case-insensitive compare.
MembershipUser membershipUser = Membership.GetUser();
string strUserId = membershipUser.ProviderUserKey.ToString();
Guid userId = new Guid(strUserId.ToUpper());
lblUserId.Text = userId.ToString();
DataModelEntities dc = new DataModelEntities();
var userTasks = dc.tasks.Where(t => t.user_id == userId).ToList();
How do I compare the GUIDs and find matches regardless of case?
UPDATE 1 now coverting the guid out of the membership provider to a GUID
Guid userId = (Guid) membershipUser.ProviderUserKey;
BUt I'm still not getting any matches.
Comparing strings in a case insensitive manner means to compare them without taking care of the uppercase and lowercase letters. To perform this operation the most preferred method is to use either toUpperCase() or toLowerCase() function.
The CompareTo method compares the GUIDs as if they were values provided to the Guid constructor, as follows: It compares the Int32 values, and returns a result if they are unequal. If they are equal, it performs the next comparison. It compares the first Int16 values, and returns a result if they are unequal.
LINQ has no concept of case sensitivity, it only cares about boolean evaluation. So if you want to ignore case, you should do something like: query = query.
CompareTo and Compare(String, String) methods. They all perform a case-sensitive comparison.
The == is overloaded on Guid so you don't need to compare the string representations.
See http://msdn.microsoft.com/en-us/library/system.guid.op_equality(v=VS.90).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With