问题
I am writing an L2E query to compare two GUID values.It simply doesn't allow direct comparison, and also .ToString() method is not allowed on L2E queries.. How can we achieve this?
回答1:
I don't know if this applies to your case, but I found that I can use the Guid.CompareTo method in Linq, and it properly converts this to SQL.
documentQuery.Where(s => s.DocumentGuid.CompareTo(MyGuidVariable) > 0);
This produces the following SQL:
AND ([Extent1].[DocumentGuid] > @p__linq__1)
回答2:
you need to compare string represantation of both the GUID parameters
string var1=Convert.ToString(GuidParam1);
string var2=Convert.ToString(GuidParam2)
then compare those string values
if(var1.CompareTo(var2)==0)
来源:https://stackoverflow.com/questions/14116986/how-to-compare-two-guids-in-linq-to-entities