Fix: The argument types 'Edm.Guid' and 'Edm.String' are incompatible for this operation.

This one had me going for a while until I found the tip in Julie Lerman’s essential book,  Programming Entity Framework, 2nd Edition.

In my ASP.NET 4 project, I create an Entity SQL query to look up a GUID. I cast the GUID as a string and wrap it in single quotes like this (non-working code):

strwhere = "(it.BusActivityID=" & busActivityID.ToString & _
        " AND it.UserID='" & mem.ProviderUserKey.ToString() & "' )"

This produces the following error message:

“The argument types 'Edm.Guid' and 'Edm.String' are incompatible for this operation. Near equals expression, line 6, column 34. “

The fix is to escape the GUID for Entity SQL. You jam in the escape literal GUID and a space  just before the quoted GUID string:

strwhere = "(it.BusActivityID=" & busActivityID.ToString & _ 
  " AND it.UserID=GUID '" & mem.ProviderUserKey.ToString() & "' )"

It turns out there are a whole whack of these escape keyword/literal thingies listed here:

Literals (Entity SQL)

http://msdn.microsoft.com/en-us/library/bb399176.aspx

Sheesh. Why do I lose time on things like this?

Ken

Published Monday, November 1, 2010 12:26 PM by Ken Cox [MVP]

Comments

# re: Fix: The argument types 'Edm.Guid' and 'Edm.String' are incompatible for this operation.

Wednesday, November 10, 2010 11:56 AM by Tony Albutt

Thanks, would not have tried it.UserId=GUID 'xxxx'

# re: Fix: The argument types 'Edm.Guid' and 'Edm.String' are incompatible for this operation.

Monday, November 29, 2010 7:34 AM by Sachin

Good stuff. It worked for me . Thanks

# re: Fix: The argument types 'Edm.Guid' and 'Edm.String' are incompatible for this operation.

Friday, June 10, 2011 9:48 PM by Larry

Thanks, what an awesome, quick and easy find. And I have that book too. Google's quicker though. :-)

# re: Fix: The argument types 'Edm.Guid' and 'Edm.String' are incompatible for this operation.

Tuesday, November 22, 2011 10:00 PM by MS-pray

Entity SQL - ah, joy! MS again "recycling" old languages with new "flavors". Just gave me a great boost (bust) in productivity, thanks guys.

Well said Ken - "Why do I lose time on things like this?"

# re: Fix: The argument types 'Edm.Guid' and 'Edm.String' are incompatible for this operation.

Sunday, May 6, 2012 1:34 PM by Joey Hendrix

Been banging my head all day trying to figure this one out. Thanks for the answer. It worked!

# re: Fix: The argument types 'Edm.Guid' and 'Edm.String' are incompatible for this operation.

Wednesday, June 13, 2012 1:58 PM by Frank

Very good article, you save me with this post!!.. thank you!!

# re: Fix: The argument types 'Edm.Guid' and 'Edm.String' are incompatible for this operation.

Sunday, October 28, 2012 3:57 PM by Deon

Thanks Ken - saved me a few gray hairs :)

# re: Fix: The argument types 'Edm.Guid' and 'Edm.String' are incompatible for this operation.

Monday, August 19, 2013 5:32 AM by Sree

You saved me with this article!!! thanks a lot.

Leave a Comment

(required) 
(required) 
(optional)
(required)