如何执行不区分大小写的GUID与LINQ的比较? [英] How do I perform a case-insensitive compare of GUIDs with LINQ?
问题描述
在下面的code,我想比较两个的GUID。问题是我没有得到任何返回的任务,因为GUID是不同的情况下(大写与小写)。我需要执行不区分大小写的比较。
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();
我如何比较的GUID,找到案件的比赛不管?
How do I compare the GUIDs and find matches regardless of case?
更新1 现在coverting的GUID出来的成员资格提供为GUID
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.
推荐答案
不知道为什么你对它们进行比较,文本,但不是 t.user_id ==用户id
使用 t.userId.Equals(用户ID,StringComparison.OrdinalIgnoreCase)
Not sure why you're comparing them as text, but instead of t.user_id == userId
use t.userId.Equals(userId, StringComparison.OrdinalIgnoreCase)
这篇关于如何执行不区分大小写的GUID与LINQ的比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!