Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare two GUIDs in Linq to Entities

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?

like image 314
Nirman Avatar asked Dec 12 '22 19:12

Nirman


1 Answers

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)
like image 137
Eric Avatar answered Jan 25 '23 01:01

Eric