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