Using Linq2Entities (EF4), I need to request an object that has the Guid
property (name it id
). I need to ask if my object has any records for which the id
begins with this prefix.
In essence, I need something like
from items in myEntity where items.id.ToString().StartsWith(prefix)
Now I know that L2EF does not support conversion of Guid
members using ToString()
.
The SqlFunctions.StringConvert()
helper does not support it, since it does not accept the Guid
argument.
And I can not use SQL LIKE
, as in
from items in myEntity where items.id like 'prefix%'
because it is also not supported by L2EF.
All the recommendations that I have found so far suggest using Contains()
, but it's just not the same as starts with
.... In the case of Guid
s, for example, the first 8 characters can be found in the last 13 characters.
So, how will you use L2EF to request records that have a Guid starting with a "prefix"?
I might think of some hacks, such as converting a uniqueidentifier
field to a back-end SQL database in varchar()
, but I would really like to understand if I'm just doing it wrong before resorting to something like that.
source share